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: no error reported for duplicate module paths among modules in go.work #54048

Open
findleyr opened this issue Jul 25, 2022 · 4 comments
Open
Labels
GoCommand help wanted modules NeedsFix
Milestone

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented Jul 25, 2022

Spin off from #53933, where gopls did not present a workspace error for a problematic go.work file because the go command was happy.

The go command does not return an error for duplicate module paths in a go.work file. Instead, it happily lets the last directory win:

$ ls -R
.:
go.work  mod1  mod2

./mod1:
a.go  go.mod

./mod2:
a.go  go.mod
$ cat go.work
go 1.19

use (
        ./mod1
        ./mod2
)
$ cat mod1/go.mod
module golang.org/foo

go 1.18
$ cat mod2/go.mod
module golang.org/foo

go 1.18
$ go list -m -json all
{
        "Path": "golang.org/foo",
        "Main": true,
        "Dir": "/home/rfindley/tmp/duplmodpath/mod2",
        "GoMod": "/home/rfindley/tmp/duplmodpath/mod2/go.mod",
        "GoVersion": "1.18"
}

CC @bcmills

@findleyr findleyr changed the title cmd/go: no error reported for duplicate module paths in go.work file cmd/go: no error reported for duplicate module paths among modules in go.work Jul 25, 2022
@cherrymui cherrymui added the NeedsInvestigation label Jul 25, 2022
@cherrymui cherrymui added this to the Backlog milestone Jul 25, 2022
@cherrymui cherrymui added the GoCommand label Jul 25, 2022
@bcmills
Copy link
Member

@bcmills bcmills commented Jul 25, 2022

We do check that the same directory doesn't appear multiple times:
https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/modload/init.go;l=583-585;drc=86b5f6a7be707b9d84108df6f459c7e84bf9dbac

However, we haven't parsed the actual go.mod files at that point and can't check for duplicate module directives.
Probably the right place to do this check is in the makeMainModules helper-function here:
https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/modload/init.go;l=1011;drc=2ff563a00e45308fad74f1f86d816f4f636584a0

@bcmills bcmills added help wanted NeedsFix labels Jul 25, 2022
@gopherbot gopherbot removed the NeedsInvestigation label Jul 25, 2022
@ianwoolf
Copy link
Contributor

@ianwoolf ianwoolf commented Jul 26, 2022

i'm working on it. i will send a cl.

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 26, 2022

Change https://go.dev/cl/419557 mentions this issue: cmd/go/internal/modload: return error when duplicate module paths among modules in go.work

@ianwoolf
Copy link
Contributor

@ianwoolf ianwoolf commented Aug 9, 2022

please feel free to review, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand help wanted modules NeedsFix
Projects
None yet
Development

No branches or pull requests

5 participants