-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: fix listing of ambiguous paths
Passing ambiguous patterns, ending in `.go`, to `go list` results in them being interpreted as Go files despite potentially being package references. This can then result in errors on other package references. The parsing logic is modified to check for a locally present file corresponding to any pattern ending in `.go`. If no such file is present the pattern is considered to be a package reference. We're also adding a variety of non-regression tests that fail with the original parsing code but passes after applying the fix. Fixes #32483 Fixes #34653 Change-Id: I073871da0dfc5641a359643f95ac14608fdca09b GitHub-Last-Rev: 5abc200 GitHub-Pull-Request: #34663 Reviewed-on: https://go-review.googlesource.com/c/go/+/198459 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
- Loading branch information
1 parent
a704224
commit 8c74bfb
Showing
4 changed files
with
51 additions
and
20 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
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
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,37 @@ | ||
# Ensures that we can correctly list package patterns ending in '.go'. | ||
# See golang.org/issue/34653. | ||
|
||
# A single pattern for a package ending in '.go'. | ||
go list ./foo.go | ||
stdout '^test/foo.go$' | ||
|
||
# Multiple patterns for packages including one ending in '.go'. | ||
go list ./bar ./foo.go | ||
stdout '^test/bar$' | ||
stdout '^test/foo.go$' | ||
|
||
# A single pattern for a Go file. | ||
go list ./a.go | ||
stdout '^command-line-arguments$' | ||
|
||
# A single typo-ed pattern for a Go file. This should | ||
# treat the wrong pattern as if it were a package. | ||
! go list ./foo.go/b.go | ||
stderr 'package ./foo.go/b.go: cannot find package "."' | ||
|
||
# Multiple patterns for Go files with a typo. This should | ||
# treat the wrong pattern as if it were a non-existint file. | ||
! go list ./foo.go/a.go ./foo.go/b.go | ||
[windows] stderr './foo.go/b.go: The system cannot find the file specified' | ||
[!windows] stderr './foo.go/b.go: no such file or directory' | ||
|
||
-- a.go -- | ||
package main | ||
-- bar/a.go -- | ||
package bar | ||
-- foo.go/a.go -- | ||
package foo.go | ||
-- go.mod -- | ||
module "test" | ||
|
||
go 1.13 |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
# go list should fail to load a package ending with ".go" since that denotes | ||
# a source file. However, ".go/" should work. | ||
# TODO(golang.org/issue/32483): perhaps we should treat non-existent paths | ||
# with .go suffixes as package paths instead. | ||
! go list example.com/dotgo.go | ||
# go list should succeed to load a package ending with ".go" if the path does | ||
# not correspond to an existing local file. Listing a pattern ending with | ||
# ".go/" should try to list a package regardless of whether a file exists at the | ||
# path without the suffixed "/" or not. | ||
go list example.com/dotgo.go | ||
stdout ^example.com/dotgo.go$ | ||
go list example.com/dotgo.go/ | ||
stdout ^example.com/dotgo.go$ | ||
|
||
|
@@ -15,9 +16,6 @@ go get -d example.com/[email protected] | |
go get -d example.com/dotgo.go/@v1.0.0 | ||
|
||
# go get (without -d) should also succeed in either case. | ||
# TODO(golang.org/issue/32483): we should be consistent with 'go build', | ||
# 'go list', and other commands. 'go list example.com/dotgo.go' (above) and | ||
# 'go get example.com/dotgo.go' should both succeed or both fail. | ||
[short] skip | ||
go get example.com/dotgo.go | ||
go get example.com/dotgo.go/ | ||
|