mirror of
https://github.com/golang/go
synced 2024-11-17 05:54:46 -07: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:
parent
5c6f42773c
commit
751aea8f19
@ -203,7 +203,12 @@ func Import(path string) (m module.Version, dir string, err error) {
|
|||||||
latest := map[string]string{} // path -> version
|
latest := map[string]string{} // path -> version
|
||||||
for _, r := range modFile.Replace {
|
for _, r := range modFile.Replace {
|
||||||
if maybeInModule(path, r.Old.Path) {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,10 @@ replace (
|
|||||||
example.com/v => ./v
|
example.com/v => ./v
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace (
|
||||||
|
example.com/i v2.0.0+incompatible => ./i2
|
||||||
|
)
|
||||||
|
|
||||||
-- m.go --
|
-- m.go --
|
||||||
package main
|
package main
|
||||||
import (
|
import (
|
||||||
@ -61,6 +65,7 @@ import (
|
|||||||
_ "example.com/x/v3"
|
_ "example.com/x/v3"
|
||||||
_ "example.com/y/z/w"
|
_ "example.com/y/z/w"
|
||||||
_ "example.com/v"
|
_ "example.com/v"
|
||||||
|
_ "example.com/i"
|
||||||
)
|
)
|
||||||
func main() {}
|
func main() {}
|
||||||
|
|
||||||
@ -115,6 +120,11 @@ module v.localhost
|
|||||||
-- v/v.go --
|
-- v/v.go --
|
||||||
package v
|
package v
|
||||||
|
|
||||||
|
-- i2/go.mod --
|
||||||
|
module example.com/i
|
||||||
|
-- i2/i.go --
|
||||||
|
package i
|
||||||
|
|
||||||
-- fail/m.go --
|
-- fail/m.go --
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user