]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: return error when duplicate module paths among modules in...
authorianwoolf <btw515wolf2@gmail.com>
Tue, 26 Jul 2022 13:55:26 +0000 (21:55 +0800)
committerGopher Robot <gobot@golang.org>
Mon, 29 Aug 2022 14:48:48 +0000 (14:48 +0000)
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>

src/cmd/go/internal/modload/init.go
src/cmd/go/testdata/script/work_issue54048.txt [new file with mode: 0644]
src/cmd/go/testdata/script/work_sum_mismatch.txt

index f960edd251d90a11b925b5276a024fb179e9350e..69a3bc8bfe3df37c53ae45e719f62c7ba2ca7318 100644 (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)
diff --git a/src/cmd/go/testdata/script/work_issue54048.txt b/src/cmd/go/testdata/script/work_issue54048.txt
new file mode 100644 (file)
index 0000000..ced3d90
--- /dev/null
@@ -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
index 9e9474304e5fe6aed4ecabc0aeea2bb43a0a92c3..ca5d71dc5e73c73a213488ca6518ad3e000367c0 100644 (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 --