Skip to content

Commit b1ddcbb

Browse files
committed
Use default importer when inside GOROOT
Signed-off-by: Kevin Mu <[email protected]>
1 parent 2caa4bd commit b1ddcbb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

importer.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (gp GoPath) PathOf(pkg string) (string, error) {
4747
// DefaultGoPath contains the default list of go paths provided either via
4848
// GOPATH environment variable or the default value.
4949
var DefaultGoPath = GoPath(filepath.SplitList(build.Default.GOPATH))
50+
var DefaultGoRoot = build.Default.GOROOT
5051

5152
// FileFilter returns true if the given file needs to be kept.
5253
type FileFilter func(pkgPath, file string, typ FileType) bool
@@ -146,7 +147,7 @@ func (i *Importer) ImportFromWithFilters(path, srcDir string, mode types.ImportM
146147
// If it's not on the GOPATH use the default importer instead
147148
useDefaultImporter := true
148149
for _, p := range DefaultGoPath {
149-
if strings.HasPrefix(root, p) {
150+
if strings.HasPrefix(root, p) && !strings.HasPrefix(root, DefaultGoRoot) {
150151
useDefaultImporter = false
151152
break
152153
}

0 commit comments

Comments
 (0)