cmd/go/internal/modload: return error when duplicate module paths among modules in go.work

Fixes #54048

Change-Id: I27350af451ff50532856092f2d99b6cc6dc6743d
Reviewed-on: https://go-review.googlesource.com/c/go/+/419557
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
ianwoolf 2022-07-26 21:55:26 +08:00 committed by Gopher Robot
parent 7f92ccea5c
commit 863d57cc7d
3 changed files with 23 additions and 1 deletions

View File

@ -993,6 +993,9 @@ func makeMainModules(ms []module.Version, rootDirs []string, modFiles []*modfile
}
mainModulePaths := make(map[string]bool)
for _, m := range ms {
if mainModulePaths[m.Path] {
base.Errorf("go: module %s appears multiple times in workspace", m.Path)
}
mainModulePaths[m.Path] = true
}
replacedByWorkFile := make(map[string]bool)

View File

@ -0,0 +1,19 @@
! go list -m -json all
stderr 'go: module example.com/foo appears multiple times in workspace'
-- go.work --
go 1.18
use (
./a
./b
)
-- a/go.mod --
module example.com/foo
go 1.18
-- b/go.mod --
module example.com/foo
go 1.18

View File

@ -42,7 +42,7 @@ func main() {
-- b/go.mod --
go 1.18
module example.com/hi
module example.com/hi2
require "rsc.io/quote" v1.5.2
-- b/go.sum --