go/loader: ignore (*build.Package).Goroot flag when handling "unsafe"
For the default build.Context, the Package.Goroot flag indicates when a
package was loaded from the standard library. Until now, the loader
used it to enable the typechecker's intrinsics for the "unsafe" package.
This seemed like a good check, but it is troublesome for clients that
use a nonstandard build.Context. For example, if a client defines
nonstandard Context hooks that load all packages, whether standard or
user-defined, from a flat sstable, there is no way for those hooks to
indicate which packages should have this flag set and which not. As a
result the contents of the "unsafe" package directory are treated as Go
source code when they are merely documentation.
Change-Id: Iea0a7cc9877507d73606391293971a28279c4e4b
Reviewed-on: https://go-review.googlesource.com/19188
Reviewed-by: Robert Griesemer <gri@golang.org>
diff --git a/go/loader/loader.go b/go/loader/loader.go
index b0f8336..23cb68c 100644
--- a/go/loader/loader.go
+++ b/go/loader/loader.go
@@ -711,7 +711,7 @@
// 'x': include external *_test.go source files. (XTestGoFiles)
//
func (conf *Config) parsePackageFiles(bp *build.Package, which rune) ([]*ast.File, []error) {
- if bp.Goroot && bp.ImportPath == "unsafe" {
+ if bp.ImportPath == "unsafe" {
return nil, nil
}
var filenames []string
@@ -767,7 +767,7 @@
// The standard unsafe package is handled specially,
// and has no PackageInfo.
- if bp.Goroot && bp.ImportPath == "unsafe" {
+ if bp.ImportPath == "unsafe" {
return types.Unsafe, nil
}