aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorianwoolf <btw515wolf2@gmail.com>2022-07-26 21:55:26 +0800
committerGopher Robot <gobot@golang.org>2022-08-29 14:48:48 +0000
commit863d57cc7df5b1604d501892b7293efe0fa7e690 (patch)
tree55fe9dbe2d97c847959a8d12ea35f49d4def5fdc
parent7f92ccea5ca5832a1dc63c02fc71db2d698f7915 (diff)
downloadgo-863d57cc7df5b1604d501892b7293efe0fa7e690.tar.xz
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>
-rw-r--r--src/cmd/go/internal/modload/init.go3
-rw-r--r--src/cmd/go/testdata/script/work_issue54048.txt19
-rw-r--r--src/cmd/go/testdata/script/work_sum_mismatch.txt2
3 files changed, 23 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index f960edd251..69a3bc8bfe 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -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)
diff --git a/src/cmd/go/testdata/script/work_issue54048.txt b/src/cmd/go/testdata/script/work_issue54048.txt
new file mode 100644
index 0000000000..ced3d9074a
--- /dev/null
+++ b/src/cmd/go/testdata/script/work_issue54048.txt
@@ -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
diff --git a/src/cmd/go/testdata/script/work_sum_mismatch.txt b/src/cmd/go/testdata/script/work_sum_mismatch.txt
index 9e9474304e..ca5d71dc5e 100644
--- a/src/cmd/go/testdata/script/work_sum_mismatch.txt
+++ b/src/cmd/go/testdata/script/work_sum_mismatch.txt
@@ -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 --