cmd/go: reject the -modfile
flag in workspace mode
#59996
Labels
FrozenDueToAge
GoCommand
cmd/go
help wanted
modules
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. And reproduce on gotip too.
What operating system and processor architecture are you using (
go env
)?go env
What did you do?
I run
go run
with the-modfile
flag in a workspace:$ go run -modfile ./m1/go.mod ./m1
directory structure and files
go.work:
m1/go.mod:
m1/main.go:
m2/go.mod:
m2/main.go:
What did you expect to see?
It runs the program or displays more friendly error message.
What did you see instead?
What's wrong?
go/src/cmd/go/internal/modload/init.go
Lines 530 to 535 in 2fd8c5b
When
-modfile
is specified, the funcmodFilePath
ignores the parametermodRoot
and returns the specified mod file stored incfg.ModFile
directly. This is incorrect in workspace mode when there are multiple mod roots (specified by the use directive) because all the mod roots will be resolved to the samego.mod
file.go/src/cmd/go/internal/modload/init.go
Lines 730 to 731 in 2fd8c5b
I would like to work on this issue. But I'm not sure what should we do about it. The most simple fix is to prevent the
-modfile
flag in workspace mode. Opinions?The text was updated successfully, but these errors were encountered: