-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: save sums for zips needed to diagnose ambiguous imports
Previously, we would retain entries in go.sum for .mod files in the module graph (reachable from the main module) and for .zip files of modules providing packages. This isn't quite enough: when we load a package, we need the content of each module in the build list that *could* provide the package (that is, each module whose path is a prefix of the package's path) so we can diagnose ambiguous imports. For #33008 Change-Id: I0b4d9d68c1f4ca382f0983a3a7e537764f35c3aa Reviewed-on: https://go-review.googlesource.com/c/go/+/262781 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com>
- Loading branch information
Jay Conrod
committed
Oct 23, 2020
1 parent
5cd4390
commit 4fdb98d
Showing
4 changed files
with
138 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/cmd/go/testdata/mod/example.com_ambiguous_a_b_v0.0.0-empty.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Module example.com/ambiguous/a/b is a suffix of example.com/a. | ||
This version contains no package. | ||
-- .mod -- | ||
module example.com/ambiguous/a/b | ||
|
||
go 1.16 | ||
-- .info -- | ||
{"Version":"v0.0.0-empty"} | ||
-- go.mod -- | ||
module example.com/ambiguous/a/b | ||
|
||
go 1.16 |
18 changes: 18 additions & 0 deletions
18
src/cmd/go/testdata/mod/example.com_ambiguous_a_v1.0.0.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Module example.com/ambiguous/a is a prefix of example.com/a/b. | ||
It contains package example.com/a/b. | ||
-- .mod -- | ||
module example.com/ambiguous/a | ||
|
||
go 1.16 | ||
|
||
require example.com/ambiguous/a/b v0.0.0-empty | ||
-- .info -- | ||
{"Version":"v1.0.0"} | ||
-- go.mod -- | ||
module example.com/ambiguous/a | ||
|
||
go 1.16 | ||
|
||
require example.com/ambiguous/a/b v0.0.0-empty | ||
-- b/b.go -- | ||
package b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Confirm our build list. | ||
cp go.sum.buildlist-only go.sum | ||
go list -m all | ||
stdout '^example.com/ambiguous/a v1.0.0$' | ||
stdout '^example.com/ambiguous/a/b v0.0.0-empty$' | ||
|
||
# If two modules could provide a package, but only one does, | ||
# 'go mod tidy' should retain sums for both zips. | ||
go mod tidy | ||
grep '^example.com/ambiguous/a v1.0.0 h1:' go.sum | ||
grep '^example.com/ambiguous/a/b v0.0.0-empty h1:' go.sum | ||
|
||
# If two modules could provide a package, and we're missing a sum for one, | ||
# we should see a missing sum error, even if we have a sum for a module that | ||
# provides the package. | ||
cp go.sum.a-only go.sum | ||
! go list example.com/ambiguous/a/b | ||
stderr '^missing go.sum entry needed to verify package example.com/ambiguous/a/b is provided by exactly one module$' | ||
! go list -deps . | ||
stderr '^use.go:3:8: missing go.sum entry needed to verify package example.com/ambiguous/a/b is provided by exactly one module; try ''go mod tidy'' to add it$' | ||
|
||
cp go.sum.b-only go.sum | ||
! go list example.com/ambiguous/a/b | ||
stderr '^missing go.sum entry for module providing package example.com/ambiguous/a/b$' | ||
! go list -deps . | ||
stderr '^use.go:3:8: missing go.sum entry for module providing package example.com/ambiguous/a/b; try ''go mod tidy'' to add it$' | ||
|
||
-- go.mod -- | ||
module m | ||
|
||
go 1.15 | ||
|
||
require example.com/ambiguous/a v1.0.0 | ||
-- go.sum.buildlist-only -- | ||
example.com/ambiguous/a v1.0.0/go.mod h1:TrBl/3xTPFJ2gmMIYz53h2gkNtg0dokszEMuyS1QEb0= | ||
example.com/ambiguous/a/b v0.0.0-empty/go.mod h1:MajJq5jPEBnnXP+NTWIeXX7kwaPS1sbVEJdooTmsePQ= | ||
-- go.sum.a-only -- | ||
example.com/ambiguous/a v1.0.0 h1:pGZhTXy6+titE2rNfwHwJykSjXDR4plO52PfZrBM0T8= | ||
example.com/ambiguous/a v1.0.0/go.mod h1:TrBl/3xTPFJ2gmMIYz53h2gkNtg0dokszEMuyS1QEb0= | ||
example.com/ambiguous/a/b v0.0.0-empty/go.mod h1:MajJq5jPEBnnXP+NTWIeXX7kwaPS1sbVEJdooTmsePQ= | ||
-- go.sum.b-only -- | ||
example.com/ambiguous/a v1.0.0/go.mod h1:TrBl/3xTPFJ2gmMIYz53h2gkNtg0dokszEMuyS1QEb0= | ||
example.com/ambiguous/a/b v0.0.0-empty h1:xS29ReXXuhjT7jc79mo91h/PevaZ2oS9PciF1DucXtg= | ||
example.com/ambiguous/a/b v0.0.0-empty/go.mod h1:MajJq5jPEBnnXP+NTWIeXX7kwaPS1sbVEJdooTmsePQ= | ||
-- use.go -- | ||
package use | ||
|
||
import _ "example.com/ambiguous/a/b" |