Commit 0b3807a2 authored by Robert Griesemer's avatar Robert Griesemer

go/types, go/importer: importing package unsafe is responsibility of importer

TBR adonovan

Fixes #13882.

Change-Id: I8664669f5d6adfec6f16e154263b1f0ea8988175
Reviewed-on: https://go-review.googlesource.com/18445Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
parent 1f26864f
......@@ -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
}
......
......@@ -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.
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment