Skip to content

Commit

Permalink
go/types, go/importer: importing package unsafe is responsibility of …
Browse files Browse the repository at this point in the history
…importer

TBR adonovan

Fixes #13882.

Change-Id: I8664669f5d6adfec6f16e154263b1f0ea8988175
Reviewed-on: https://go-review.googlesource.com/18445
Reviewed-by: Robert Griesemer <gri@golang.org>
  • Loading branch information
griesemer committed Jan 9, 2016
1 parent 1f26864 commit 0b3807a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/go/internal/gcimporter/gcimporter.go
Expand Up @@ -112,13 +112,11 @@ func ImportData(packages map[string]*types.Package, filename, id string, data io
// 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
}
Expand Down
9 changes: 5 additions & 4 deletions src/go/types/api.go
Expand Up @@ -112,11 +112,12 @@ type Config struct {
// 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.
Expand Down
3 changes: 0 additions & 3 deletions src/go/types/resolver.go
Expand Up @@ -183,9 +183,6 @@ func (check *Checker) collectObjects() {
// 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 {
Expand Down

0 comments on commit 0b3807a

Please sign in to comment.