diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 147917c46f..c169ec7db8 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -967,6 +967,14 @@ func TestInternalPackageErrorsAreHandled(t *testing.T) { tg.run("list", "./testdata/testinternal3") } +func TestInternalCache(t *testing.T) { + tg := testgo(t) + defer tg.cleanup() + tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/testinternal4")) + tg.runFail("build", "p") + tg.grepStderr("internal", "did not fail to build p") +} + func TestMoveGit(t *testing.T) { testMove(t, "git", "rsc.io/pdf", "pdf", "rsc.io/pdf/.git/config") } diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go index e6c17036fe..95b5eb347a 100644 --- a/src/cmd/go/pkg.go +++ b/src/cmd/go/pkg.go @@ -882,7 +882,13 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package deps[path] = p1 imports = append(imports, p1) for _, dep := range p1.deps { - deps[dep.ImportPath] = dep + // Do not overwrite entries installed by direct import + // just above this loop. Those have stricter constraints + // about internal and vendor visibility and may contain + // errors that we need to preserve. + if deps[dep.ImportPath] == nil { + deps[dep.ImportPath] = dep + } } if p1.Incomplete { p.Incomplete = true diff --git a/src/cmd/go/testdata/testinternal4/src/p/p.go b/src/cmd/go/testdata/testinternal4/src/p/p.go new file mode 100644 index 0000000000..6bdee27be2 --- /dev/null +++ b/src/cmd/go/testdata/testinternal4/src/p/p.go @@ -0,0 +1,6 @@ +package p + +import ( + _ "q/internal/x" + _ "q/j" +) diff --git a/src/cmd/go/testdata/testinternal4/src/q/internal/x/x.go b/src/cmd/go/testdata/testinternal4/src/q/internal/x/x.go new file mode 100644 index 0000000000..823aafd071 --- /dev/null +++ b/src/cmd/go/testdata/testinternal4/src/q/internal/x/x.go @@ -0,0 +1 @@ +package x diff --git a/src/cmd/go/testdata/testinternal4/src/q/j/j.go b/src/cmd/go/testdata/testinternal4/src/q/j/j.go new file mode 100644 index 0000000000..9f07543894 --- /dev/null +++ b/src/cmd/go/testdata/testinternal4/src/q/j/j.go @@ -0,0 +1,3 @@ +package j + +import _ "q/internal/x"