Skip to content

Commit

Permalink
cmd/go: add a test that reproduces the root cause of issue #56494
Browse files Browse the repository at this point in the history
For #56494.

Change-Id: I9bbded6d014ac73d81b973f2d7b4783e64380031
Reviewed-on: https://go-review.googlesource.com/c/go/+/447797
Run-TryBot: Bryan Mills <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed May 17, 2023
1 parent 7bc3281 commit 9fd8769
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modget/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
Expand Down
136 changes: 136 additions & 0 deletions src/cmd/go/testdata/script/mod_get_issue56494.txt
Original file line number Diff line number Diff line change
@@ -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 [email protected]
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

0 comments on commit 9fd8769

Please sign in to comment.