Skip to content

Commit c4f875e

Browse files
author
Jay Conrod
committed
cmd/go: report original module path in error parsing replaced go.mod
MVS reports an error when a go.mod file declares a module path that doesn't match the path it was required with. If the module is a replacement, its declared path may be the original path (preferred) or the replacement path. This CL makes the reported error a little more clear: the "required as" path should be the original required path, not the replacement path. Fixes #38220 Change-Id: I08b50a100679a447c8803cca1d1b32bc115ec1b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/227097 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent d786395 commit c4f875e

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/cmd/go/internal/modload/mvs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (r *mvsReqs) required(mod module.Version) ([]module.Version, error) {
148148
if mpath := f.Module.Mod.Path; mpath != origPath && mpath != mod.Path {
149149
return nil, module.VersionError(mod, fmt.Errorf(`parsing go.mod:
150150
module declares its path as: %s
151-
but was required as: %s`, mpath, mod.Path))
151+
but was required as: %s`, mpath, origPath))
152152
}
153153
if f.Go != nil {
154154
r.versions.LoadOrStore(mod, f.Go.Version)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This module is a replacement for rsc.io/quote, but its go.mod file declares
2+
a module path different from its location and the original module.
3+
4+
-- .mod --
5+
module rsc.io/Quote
6+
7+
go 1.14
8+
-- .info --
9+
{"Version":"v1.5.2"}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# If a replacement module declares a module path different from both
2+
# the original module and its location, report an error with all three paths.
3+
# In particular, the "required as" path should be the original.
4+
# Verifies golang.org/issue/38220.
5+
! go list .
6+
cmp stderr want
7+
8+
-- go.mod --
9+
module m
10+
11+
require rsc.io/quote v1.5.2
12+
13+
replace rsc.io/quote v1.5.2 => example.com/quote v1.5.2
14+
15+
-- use.go --
16+
package use
17+
18+
import _ "rsc.io/quote"
19+
20+
-- want --
21+
go: example.com/[email protected]: parsing go.mod:
22+
module declares its path as: rsc.io/Quote
23+
but was required as: rsc.io/quote

0 commit comments

Comments
 (0)