Skip to content

Commit 751aea8

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> Reviewed-by: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 5c6f427 commit 751aea8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/cmd/go/internal/modload/import.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,12 @@ func Import(path string) (m module.Version, dir string, err error) {
203203
latest := map[string]string{} // path -> version
204204
for _, r := range modFile.Replace {
205205
if maybeInModule(path, r.Old.Path) {
206-
latest[r.Old.Path] = semver.Max(r.Old.Version, latest[r.Old.Path])
206+
// Don't use semver.Max here; need to preserve +incompatible suffix.
207+
v := latest[r.Old.Path]
208+
if semver.Compare(r.Old.Version, v) > 0 {
209+
v = r.Old.Version
210+
}
211+
latest[r.Old.Path] = v
207212
}
208213
}
209214

src/cmd/go/testdata/script/mod_replace_import.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,18 @@ replace (
5454
example.com/v => ./v
5555
)
5656

57+
replace (
58+
example.com/i v2.0.0+incompatible => ./i2
59+
)
60+
5761
-- m.go --
5862
package main
5963
import (
6064
_ "example.com/a/b"
6165
_ "example.com/x/v3"
6266
_ "example.com/y/z/w"
6367
_ "example.com/v"
68+
_ "example.com/i"
6469
)
6570
func main() {}
6671

@@ -115,6 +120,11 @@ module v.localhost
115120
-- v/v.go --
116121
package v
117122

123+
-- i2/go.mod --
124+
module example.com/i
125+
-- i2/i.go --
126+
package i
127+
118128
-- fail/m.go --
119129
package main
120130

0 commit comments

Comments
 (0)