diff options
author | Baokun Lee <nototon@gmail.com> | 2019-10-07 22:33:57 +0800 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2019-10-22 14:26:04 +0000 |
commit | ea726d8dc6f3fb6f02ff816d8bfafed96fc7788a (patch) | |
tree | 14ecb5317ff544e78cfadfffaa0f5fb33385592a /src/cmd/go/internal/modload/load.go | |
parent | d29c14f3d2519d72a24c7060d99935f562c37db3 (diff) | |
download | go-ea726d8dc6f3fb6f02ff816d8bfafed96fc7788a.tar.gz go-ea726d8dc6f3fb6f02ff816d8bfafed96fc7788a.zip |
cmd/go/internal/modcmd: error out if one module with two different paths
If a single module is imported via two different paths, go mod tidy
should have reported this error instead of deferring it until go build.
Fixes #34650.
Change-Id: I9d09df1551b3e2083ed9f0bc77f2989073057717
Reviewed-on: https://go-review.googlesource.com/c/go/+/199598
Run-TryBot: Baokun Lee <nototon@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r-- | src/cmd/go/internal/modload/load.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index 5f6fd672ba..a9f711733c 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -211,11 +211,17 @@ func ImportPathsQuiet(patterns []string, tags map[string]bool) []*search.Match { // 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 @@ -229,9 +235,6 @@ func ImportPathsQuiet(patterns []string, tags map[string]bool) []*search.Match { } } base.ExitIfErrors() - WriteGoMod() - - return matches } // pathInModuleCache returns the import path of the directory dir, @@ -383,6 +386,7 @@ func loadAll(testAll bool) []string { } all := TargetPackages("...") loaded.load(func() []string { return all }) + checkMultiplePaths() WriteGoMod() var paths []string |