Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: 'go list -mod=readonly' erroneously resolves imports from replaced modules #41577

bcmills opened this issue Sep 23, 2020 · 2 comments


Copy link

@bcmills bcmills commented Sep 23, 2020

When -mod=readonly is set, go list should refuse to resolve missing dependencies, and normally does.

However, if the dependency can be satisfied by adding a requirement on a module mentioned in a replace directive, the usual lookup disabled error message is suppressed, and go list instead fails with updates to go.mod needed:$ go version
go version devel +150bd4ff Wed Sep 23 07:51:17 2020 +0000 linux/amd64$ go list -mod=readonly
cannot find module providing package import lookup disabled by -mod=readonly$ go mod edit$ go list -mod=readonly
go: found in v0.1.0
go: updates to go.mod needed, disabled by -mod=readonly

-- go.mod --

go 1.16
-- x/go.mod --

go 1.16
-- x/x.go --
package x
@bcmills bcmills added this to the Go1.16 milestone Sep 23, 2020
@bcmills bcmills self-assigned this Sep 23, 2020
Copy link

@gopherbot gopherbot commented Sep 29, 2020

Change mentions this issue: cmd/go/internal/modload: rework replacements in the Query functions

gopherbot pushed a commit that referenced this issue Oct 16, 2020
'go mod tidy' has been able to use replaced versions since CL 152739,
but 'go get' failed for many of the same paths. Now that we are
recommending 'go get' more aggressively due to #40728, we should make
that work too.

In the future, we might consider factoring out the new replacementRepo
type so that 'go list' can report the new versions as well.

For #41577
For #41416
For #37438
Updates #26241

Change-Id: I9140c556424b584fdd9bdd0a747842774664a7d8
Trust: Bryan C. Mills <>
Trust: Jay Conrod <>
Run-TryBot: Bryan C. Mills <>
TryBot-Result: Go Bot <>
Reviewed-by: Michael Matloob <>
Reviewed-by: Jay Conrod <>
Copy link

@gopherbot gopherbot commented Oct 17, 2020

Change mentions this issue: cmd/go/internal/modload: fix sort condition in (*replacementRepo).Versions

gopherbot pushed a commit that referenced this issue Oct 17, 2020

In CL 258220 I added replacement versions to the repo versions used in
the modload.Query functions. The versions are computed from a map in
the modfile index, which has a nondeterministic iteration order.

I added a short-circuit condition to skip sorting in the (vastly
common) case where no replacement versions are added. However, while
cleaning up the change I accidentally deleted the line of code that
sets that condition. As a result, the test of that functionality
(mod_get_replaced) has been failing nondeterministically.

This change fixes the condition by comparing the slices before and
after adding versions, rather than by setting a separate variable.
The test now passes reliably (tested with -count=200).

Updates #41577
Updates #41416
Updates #37438
Updates #26241

Change-Id: I49a66a3a5510da00ef42b47f20a168de66100db6
Trust: Bryan C. Mills <>
Run-TryBot: Bryan C. Mills <>
TryBot-Result: Go Bot <>
Reviewed-by: Daniel Martí <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.