go: cmd/go: `go mod tidy` introduces ambiguous imports in pruned modules
What version of Go are you using (go version
)?
/tmp/census3$ go version go version devel go1.21-b60db8f7d9 Fri May 19 18:01:57 2023 +0000 linux/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/usr/local/google/home/bcmills/.cache/go-build' GOENV='/usr/local/google/home/bcmills/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GOMODCACHE='/usr/local/google/home/bcmills/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='linux' GOPATH='/usr/local/google/home/bcmills' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/usr/local/google/home/bcmills/go' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLDIR='/usr/local/google/home/bcmills/go/pkg/tool/linux_amd64' GOVCS='' GOVERSION='devel go1.21-b60db8f7d9 Fri May 19 18:01:57 2023 +0000' GCCGO='/usr/bin/gccgo' GOAMD64='v1' AR='ar' CC='gcc' CXX='c++' CGO_ENABLED='1' GOMOD='/tmp/census3/go.mod' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1942413867=/tmp/go-build -gno-record-gcc-switches'
What did you do?
Clone vocdoni/census3@559b89d34e19824f0027a0724c136f9cac694673 and go mod tidy
it twice:
$ git clone https://github.com/vocdoni/census3.git
$ git checkout 559b89d34e19824f0027a0724c136f9cac694673
$ go mod tidy
$ go mod tidy
What did you expect to see?
Both go mod tidy
operations should succeed.
What did you see instead?
The first go mod tidy
succeeds, but it removes a requirement needed to prevent an ambiguous import in a test dependency of a transitively-imported package, causing the second go mod tidy
to fail:
/tmp/census3$ go mod tidy
/tmp/census3$ go mod tidy
github.com/vocdoni/census3/contracts/aragon/want imports
github.com/ethereum/go-ethereum/accounts/abi imports
github.com/ethereum/go-ethereum/crypto imports
github.com/btcsuite/btcd/btcec/v2/ecdsa tested by
github.com/btcsuite/btcd/btcec/v2/ecdsa.test imports
github.com/btcsuite/btcd/chaincfg/chainhash: ambiguous import: found package github.com/btcsuite/btcd/chaincfg/chainhash in multiple modules:
github.com/btcsuite/btcd v0.20.1-beta (/usr/local/google/home/bcmills/pkg/mod/github.com/btcsuite/btcd@v0.20.1-beta/chaincfg/chainhash)
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 (/usr/local/google/home/bcmills/pkg/mod/github.com/btcsuite/btcd/chaincfg/chainhash@v1.0.2)
(CC @matloob)
Example courtesy of @mvdan.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 17 (7 by maintainers)
Commits related to this issue
- cmd/go: add a test that reproduces an unstable 'go mod tidy' For #60313. Change-Id: I76e48f52341e9962de9b809741a677d61baae6a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/496518 Reviewed-b... — committed to golang/go by bcmills a year ago
- cmd/go/internal/modload: address comment and test issues from CL 496635 Michael noticed some minor issues in backports of CL 496635. Those issues have been addressed in the backport CLs; this change ... — committed to golang/go by bcmills a year ago
- [release-branch.go1.20] cmd/go: retain extra roots to disambiguate imports in 'go mod tidy' We don't normally keep explicit requirements for test dependencies of packages loaded from other modules wh... — committed to golang/go by bcmills a year ago
- [release-branch.go1.19] cmd/go: retain extra roots to disambiguate imports in 'go mod tidy' We don't normally keep explicit requirements for test dependencies of packages loaded from other modules wh... — committed to golang/go by bcmills a year ago
go get github.com/btcsuite/btcd/chaincfg/chainhash
works now as chainhash just upgraded to v1.0.2.go: upgraded github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 => v1.0.2
@costela, consumers of
my.private.package
may still need togo get
a specific module to disambiguate when they first add the dependency. #27899 is the issue for that more general problem.