// One last pass to finalize wildcards.
updateMatches(matches, false)
+ checkMultiplePaths()
+ WriteGoMod()
+
+ return matches
+}
- // A given module path may be used as itself or as a replacement for another
- // module, but not both at the same time. Otherwise, the aliasing behavior is
- // too subtle (see https://golang.org/issue/26607), and we don't want to
- // commit to a specific behavior at this point.
+// checkMultiplePaths verifies that a given module path is used as itself
+// or as a replacement for another module, but not both at the same time.
+//
+// (See https://golang.org/issue/26607 and https://golang.org/issue/34650.)
+func checkMultiplePaths() {
firstPath := make(map[module.Version]string, len(buildList))
for _, mod := range buildList {
src := mod
}
}
base.ExitIfErrors()
- WriteGoMod()
-
- return matches
}
// pathInModuleCache returns the import path of the directory dir,
}
all := TargetPackages("...")
loaded.load(func() []string { return all })
+ checkMultiplePaths()
WriteGoMod()
var paths []string
cd outside
go list -m all
stdout 'rsc.io/sampler v1.3.0'
+cd ..
+
+# The same module can't be used as two different paths.
+cd multiple-paths
+! go mod tidy
+stderr 'rsc.io/quote/v3@v3.0.0 used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)'
-- go.mod --
module example.com/tidy
module golang.org/issue/30166/b
require golang.org/issue/30166/a v0.0.0
+-- multiple-paths/main.go --
+package main
+
+import (
+ "fmt"
+ "rsc.io/quote/v3"
+)
+
+func main() {
+ fmt.Println(quote.GoV3())
+}
+-- multiple-paths/go.mod --
+module quoter
+
+require (
+ rsc.io/quote/v3 v3.0.0
+ not-rsc.io/quote/v3 v3.0.0
+)
+
+replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0
! stderr 'finding'
! stderr 'lookup disabled'
+# The same module can't be used as two different paths.
+cd multiple-paths
+! go mod vendor
+stderr 'rsc.io/quote/v3@v3.0.0 used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)'
+
-- go.mod --
module example.com/replace
-- local/not-rsc.io/quote/v3/quote.go --
package quote
+
+-- multiple-paths/main.go --
+package main
+import (
+ "fmt"
+ "rsc.io/quote/v3"
+)
+func main() {
+ fmt.Println(quote.GoV3())
+}
+-- multiple-paths/go.mod --
+module quoter
+require (
+ rsc.io/quote/v3 v3.0.0
+ not-rsc.io/quote/v3 v3.0.0
+)
+replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0
\ No newline at end of file