1
0
mirror of https://github.com/golang/go synced 2024-09-29 10:24:34 -06:00

cmd/go: avoid erroneous canonicalization when trying to resolve imports using replacements

Updates #32700
Fixes #33795

Change-Id: I16897a0a2f3aa2f0b0bf8cf8252f3f39eef2e7ba
Reviewed-on: https://go-review.googlesource.com/c/go/+/212200
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Bryan C. Mills 2019-12-19 22:36:13 -05:00
parent 5c6f42773c
commit 751aea8f19
2 changed files with 16 additions and 1 deletions

View File

@ -203,7 +203,12 @@ func Import(path string) (m module.Version, dir string, err error) {
latest := map[string]string{} // path -> version
for _, r := range modFile.Replace {
if maybeInModule(path, r.Old.Path) {
latest[r.Old.Path] = semver.Max(r.Old.Version, latest[r.Old.Path])
// Don't use semver.Max here; need to preserve +incompatible suffix.
v := latest[r.Old.Path]
if semver.Compare(r.Old.Version, v) > 0 {
v = r.Old.Version
}
latest[r.Old.Path] = v
}
}

View File

@ -54,6 +54,10 @@ replace (
example.com/v => ./v
)
replace (
example.com/i v2.0.0+incompatible => ./i2
)
-- m.go --
package main
import (
@ -61,6 +65,7 @@ import (
_ "example.com/x/v3"
_ "example.com/y/z/w"
_ "example.com/v"
_ "example.com/i"
)
func main() {}
@ -115,6 +120,11 @@ module v.localhost
-- v/v.go --
package v
-- i2/go.mod --
module example.com/i
-- i2/i.go --
package i
-- fail/m.go --
package main