// The packages map must contain all packages already imported.
//
func Import(packages map[string]*types.Package, path, srcDir string) (pkg *types.Package, err error) {
- // package "unsafe" is handled by the type checker
- if path == "unsafe" {
- panic(`gcimporter.Import called for package "unsafe"`)
- }
-
filename, id := FindPkg(path, srcDir)
if filename == "" {
+ if path == "unsafe" {
+ return types.Unsafe, nil
+ }
err = fmt.Errorf("can't find import: %s", id)
return
}
// error found.
Error func(err error)
- // Importer.Import is called for each import declaration except when
- // importing package "unsafe". An error is reported if an importer is
- // needed but none was installed.
- // If the installed Importer implements Importer2, the Import2 method
+ // An importer is used to import packages referred to from
+ // import declarations.
+ // If the installed importer implements Importer2, Import2
// is called instead of Import.
+ // An error is reported if an importer is needed but none
+ // was installed.
Importer Importer
// If Sizes != nil, it provides the sizing functions for package unsafe.
// TODO(gri) shouldn't create a new one each time
imp = NewPackage("C", "C")
imp.fake = true
- } else if path == "unsafe" {
- // package "unsafe" is known to the language
- imp = Unsafe
} else {
// ordinary import
if importer := check.conf.Importer; importer == nil {