summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2022-11-03 17:12:15 -0400
committerGopher Robot <gobot@golang.org>2023-05-17 13:04:59 +0000
commit9fd876924a0bc5f94c18ae8b9dce22ad48da9a8f (patch)
tree04fbe0842a23059da5c1fd6c530c831af209b474
parent7bc3281747030877e13d218ba12c6e95fcf4e7d4 (diff)
downloadgo-git-9fd876924a0bc5f94c18ae8b9dce22ad48da9a8f.tar.gz
cmd/go: add a test that reproduces the root cause of issue #56494
For #56494. Change-Id: I9bbded6d014ac73d81b973f2d7b4783e64380031 Reviewed-on: https://go-review.googlesource.com/c/go/+/447797 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
-rw-r--r--src/cmd/go/internal/modget/get.go2
-rw-r--r--src/cmd/go/testdata/script/mod_get_issue56494.txt136
2 files changed, 137 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modget/get.go b/src/cmd/go/internal/modget/get.go
index da4d004af2..836aa5f7a5 100644
--- a/src/cmd/go/internal/modget/get.go
+++ b/src/cmd/go/internal/modget/get.go
@@ -1751,7 +1751,7 @@ func (r *resolver) updateBuildList(ctx context.Context, additions []module.Versi
reason := func(m module.Version) string {
rv, ok := r.resolvedVersion[m.Path]
if !ok {
- panic(fmt.Sprintf("internal error: can't find reason for requirement on %v", m))
+ return fmt.Sprintf("(INTERNAL ERROR: no reason found for %v)", m)
}
return rv.reason.ResolvedString(module.Version{Path: m.Path, Version: rv.version})
}
diff --git a/src/cmd/go/testdata/script/mod_get_issue56494.txt b/src/cmd/go/testdata/script/mod_get_issue56494.txt
new file mode 100644
index 0000000000..dabe23b9a7
--- /dev/null
+++ b/src/cmd/go/testdata/script/mod_get_issue56494.txt
@@ -0,0 +1,136 @@
+# Regression test for https://go.dev/issue/56494:
+# 'go get' in module mode was failing to prune out dependencies
+# through modules whose versions are too low to be selected.
+
+# Initially, modules "a", "b", and "c" are unrelated.
+#
+# The package import graph at v1 of everything looks like:
+#
+# m --- a
+# |
+# + --- b
+# |
+# + --- c
+#
+# At v2, package "a" adds imports of "b" and "c"
+# (and a requirement on "c" v2):
+#
+# a --- b
+# |
+# + --- c
+#
+# And "b" adds an import of "a/sub" (in module "a"):
+#
+# b --- a/sub
+#
+# At v3, "a" no longer imports (nor requires) "c":
+#
+# a --- b
+
+# So upgrading to a3 adds a dependency on b2,
+# b2 adds a dependency on a2 (for "a/sub"),
+# and a2 (but not a3) would add a dependency on c2.
+# Since a2 is lower than a3 it cannot possibly be selected when
+# upgrading to a3: normally a2 is pruned out of a3's module graph,
+# so 'go get' should prune it out too, and c should remain at c1
+# without error.
+
+ # TODO(#56494): This should succeed, not error out.
+! go get a@v0.3.0
+stderr 'INTERNAL ERROR'
+
+go list -m c
+stdout '^c v0.1.0 '
+
+-- go.mod --
+module m
+
+go 1.19
+
+require (
+ a v0.1.0
+ b v0.1.0
+ c v0.1.0
+)
+
+replace (
+ a v0.1.0 => ./a1
+ a v0.2.0 => ./a2
+ a v0.3.0 => ./a3
+ b v0.1.0 => ./b1
+ b v0.2.0 => ./b2
+ c v0.1.0 => ./c1
+ c v0.2.0 => ./c2
+)
+-- m.go --
+package m
+
+import (
+ _ "a"
+ _ "b"
+ _ "c"
+)
+-- a1/go.mod --
+module a
+
+go 1.19
+-- a1/a.go --
+package a
+-- a2/go.mod --
+module a
+
+go 1.19
+
+require (
+ b v0.1.0
+ c v0.2.0
+)
+-- a2/a.go --
+package a
+
+import (
+ _ "b"
+ _ "c"
+)
+-- a2/sub/sub.go --
+package sub
+-- a3/go.mod --
+module a
+
+go 1.19
+
+require b v0.2.0
+-- a3/a.go --
+package a
+
+import _ "b"
+-- a3/sub/sub.go --
+package sub
+-- b1/go.mod --
+module b
+
+go 1.19
+-- b1/b.go --
+package b
+-- b2/go.mod --
+module b
+
+go 1.19
+
+require a v0.2.0
+-- b2/b.go --
+package b
+
+import "a/sub"
+-- c1/go.mod --
+module c
+
+go 1.19
+-- c1/c.go --
+package c
+-- c2/go.mod --
+module c
+
+go 1.19
+-- c2/c.go --
+package c