From 02f1928320c505d9c43388e28907e652420406d8 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 4 Feb 2016 11:15:46 -0500 Subject: [PATCH] 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 --- go/loader/loader.go | 4 ++-- go/loader/loader14.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go/loader/loader.go b/go/loader/loader.go index b0f8336c..23cb68c6 100644 --- a/go/loader/loader.go +++ b/go/loader/loader.go @@ -711,7 +711,7 @@ func (conf *Config) build() *build.Context { // '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 @@ func (imp *importer) doImport(from *PackageInfo, to string) (*types.Package, err // 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 } diff --git a/go/loader/loader14.go b/go/loader/loader14.go index d3fb1571..4fd4b2a6 100644 --- a/go/loader/loader14.go +++ b/go/loader/loader14.go @@ -714,7 +714,7 @@ func (conf *Config) build() *build.Context { // '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 @@ -770,7 +770,7 @@ func (imp *importer) doImport(from *PackageInfo, to string) (*types.Package, err // 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 }