cmd/go: go build should not fetch replaced module if incorrectly imported #30925
Labels
FrozenDueToAge
modules
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Proposal
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When you import a module rather than a package from a module (a common mistake). i.e.:
rather than
and use the replace directive expecting go to reference a local copy of the module, go ignores the replace and attempts to fetch the module remotely regardless. If this fails (because of proxies or whatever) the build fails. The build will also fail because of the incorrect import
What appears to be happening is go ignores the replace and even though the module/package is imported incorrectly it still tries to fetch the module.
What did you expect to see?
I would expect go not to attempt the fetch (honour the replace) and throw an error on the module import.
What did you see instead?
It attempts to fetch the module. Which, when you are using a replace to avoid a fetch, breaks the build to early.
I think there is some sort of disconnect when the module instructions and the error in the code disagree with each other and it doesnt behave as I would expect.
Apologies if this is hard to follow! Its hard to explain is a simple way. Bascially if you try and import a module with out a package go seems to want to fetch the module anyway which is probably fine unless you are trying to use a replace in go.mod.
Thanks,
James
The text was updated successfully, but these errors were encountered: