Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: panic: LoadImport called with empty package path when listing GOROOT/test/*.go #60230

Closed
bcmills opened this issue May 16, 2023 · 9 comments
Assignees
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented May 16, 2023

What did you do?

~$ gotip version
go version devel go1.21-5534f044 Tue May 16 16:01:08 2023 +0000 linux/amd64

~$ cd $(gotip env GOROOT)/test

~/sdk/gotip/test$ gotip list *.go
panic: LoadImport called with empty package path

goroutine 1 [running]:
cmd/go/internal/load.loadImport({0xb57718, 0xee60e0}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, 0x0, {0xc00051f5ee, ...}, ...)
        /usr/local/google/home/bcmills/sdk/gotip/src/cmd/go/internal/load/pkg.go:727 +0x124a
cmd/go/internal/load.LoadImport(...)
        /usr/local/google/home/bcmills/sdk/gotip/src/cmd/go/internal/load/pkg.go:710
cmd/go/internal/load.(*Package).load(0xc0001bcc00, {0xb57718, 0xee60e0}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, {0xa59638, ...}, ...)
        /usr/local/google/home/bcmills/sdk/gotip/src/cmd/go/internal/load/pkg.go:2004 +0x1a49
cmd/go/internal/load.GoFilesPackage({0xb57718, 0xee60e0}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, {0xc000134020, 0x145, ...})
        /usr/local/google/home/bcmills/sdk/gotip/src/cmd/go/internal/load/pkg.go:3181 +0x827
cmd/go/internal/load.PackagesAndErrors({0xb57718?, 0xee60e0?}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, {0xc000134020, 0x145, ...})
        /usr/local/google/home/bcmills/sdk/gotip/src/cmd/go/internal/load/pkg.go:2826 +0x253
cmd/go/internal/list.runList({0xb57718?, 0xee60e0}, 0xeaad60?, {0xc000134020?, 0x145, 0x14e})
        /usr/local/google/home/bcmills/sdk/gotip/src/cmd/go/internal/list/list.go:612 +0xcf0
main.invoke(0xeaad60, {0xc000134010, 0x146, 0x14f})
        /usr/local/google/home/bcmills/sdk/gotip/src/cmd/go/main.go:243 +0x4d6
main.main()
        /usr/local/google/home/bcmills/sdk/gotip/src/cmd/go/main.go:183 +0x7cf

What did you expect to see?

An error message explaining why I can't load all of the .go files in GOROOT/test as a single package.

What did you see instead?

Panic!

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels May 16, 2023
@bcmills bcmills added this to the Backlog milestone May 16, 2023
@bcmills
Copy link
Contributor Author

bcmills commented May 16, 2023

(CC @matloob)

@bcmills
Copy link
Contributor Author

bcmills commented Jun 8, 2023

This reproduces with go1.20.5 but not go1.19.10. Seems like it was probably a regression in Go 1.20.

@bcmills
Copy link
Contributor Author

bcmills commented Jun 8, 2023

(Possibly related to #59905.)

@d-enk
Copy link

d-enk commented Jun 8, 2023

#60686

@gopherbot
Copy link

Change https://go.dev/cl/502615 mentions this issue: go/build: check for invalid import paths again

@matloob matloob self-assigned this Jun 12, 2023
@matloob
Copy link
Contributor

matloob commented Jun 12, 2023

@gopherbot, please backport to 1.20. The change in go/parser behavior between Go 1.19 and Go 1.20 caused a regression in 1.20.

@gopherbot
Copy link

Backport issue(s) opened: #60753 (for 1.19), #60754 (for 1.20).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link

Change https://go.dev/cl/502697 mentions this issue: go/build: check for invalid import paths again

@gopherbot
Copy link

Change https://go.dev/cl/502697 mentions this issue: [release-branch.go1.20] go/build: check for invalid import paths again

gopherbot pushed a commit that referenced this issue Jun 13, 2023
The go parser previously checked for invalid import paths, go/build,
seeing the parse error would put files with invalid import paths into
InvalidGoFiles. golang.org/cl/424855 removed that check from the
parser, which meant files with invalid import paths not have any parse
errors on them and not be put into InvalidGoFiles. Do a check for
invalid import paths in go/build soon after parsing so we can make
sure files with invalid import paths go into InvalidGoFiles.

This fixes an issue where the Go command assumed that if a file wasn't
invalid it had non empty import paths, leading to a panic.

Fixes #60754
Updates #60230
Updates #60686

Change-Id: I33c1dc9304649536834939cef7c689940236ee20
Reviewed-on: https://go-review.googlesource.com/c/go/+/502615
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
(cherry picked from commit 962753b)
Reviewed-on: https://go-review.googlesource.com/c/go/+/502697
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 20, 2023
@dmitshur dmitshur modified the milestones: Backlog, Go1.21 Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants