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

Closed
findleyr opened this issue Jul 25, 2022 · 4 comments
Closed
Labels
FrozenDueToAge GoCommand cmd/go help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@findleyr
Copy link
Contributor

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 Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 25, 2022
@cherrymui cherrymui added this to the Backlog milestone Jul 25, 2022
@cherrymui cherrymui added the GoCommand cmd/go label Jul 25, 2022
@bcmills
Copy link
Member

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 The path to resolution is known, but the work has not been done. labels Jul 25, 2022
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 25, 2022
@ianwoolf
Copy link
Contributor

ianwoolf commented Jul 26, 2022

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

@gopherbot
Copy link

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 commented Aug 9, 2022

please feel free to review, thanks

@bcmills bcmills modified the milestones: Backlog, Go1.20 Aug 29, 2022
@golang golang locked and limited conversation to collaborators Aug 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants