mirror of
https://github.com/golang/go
synced 2024-11-12 02:00:23 -07:00
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/18445 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
1f26864f88
commit
0b3807a2a3
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user