From d70943431397b297fe00c114dd3e97376277f09a Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 20 Jul 2015 20:05:37 -0400 Subject: [PATCH] cmd/go: fix missing internal import error Fixes #11331. Change-Id: I19b8172421044c301bc136fc8f7bfdadbf880e25 Reviewed-on: https://go-review.googlesource.com/12450 Reviewed-by: Brad Fitzpatrick Reviewed-by: Andrew Gerrand --- src/cmd/go/go_test.go | 8 ++++++++ src/cmd/go/pkg.go | 8 +++++++- src/cmd/go/testdata/testinternal4/src/p/p.go | 6 ++++++ src/cmd/go/testdata/testinternal4/src/q/internal/x/x.go | 1 + src/cmd/go/testdata/testinternal4/src/q/j/j.go | 3 +++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/cmd/go/testdata/testinternal4/src/p/p.go create mode 100644 src/cmd/go/testdata/testinternal4/src/q/internal/x/x.go create mode 100644 src/cmd/go/testdata/testinternal4/src/q/j/j.go 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"