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!

Comment From: bcmills

(CC @matloob)

Comment From: bcmills

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

Comment From: bcmills

(Possibly related to #59905.)

Comment From: d-enk

60686

Comment From: gopherbot

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

Comment From: matloob

@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.

Comment From: gopherbot

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.

Comment From: gopherbot

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

Comment From: gopherbot

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

Comment From: Chrisys93

Is this addressed in GO 1.22.3? Thank you!

Comment From: matloob

Yes, are you running into it?

Comment From: h9jiang

I first saw this error from https://github.com/golang/go/issues/74593, I'm not sure if this is relevant or not. But here is my set up (I know my set up is wrong and I'm not suppose to setup my workspace this way, I'm fixing it.....)

  • a go.mod file in ~/go.mod
  • a lot of repos under ~/Desktop/codebase/* including go itself ~/codebase/go and others like x_tools x_build

If I run go list ./... from the ~, the go program crashes with stack:


 ~// go list ./...
panic: LoadImport called with empty package path [recovered, repanicked]

goroutine 1 [running]:
cmd/go/internal/load.(*preload).flush(0x140002a2f10)
        ~/Desktop/codebase/go/src/cmd/go/internal/load/pkg.go:1122 +0x80
panic({0x104c13640?, 0x104cf9d90?})
        ~/Desktop/codebase/go/src/runtime/panic.go:783 +0x120
cmd/go/internal/load.loadImport({0x104d03070, 0x10512c8e0}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, 0x0, {0x12befa9a9, ...}, ...)
        ~/Desktop/codebase/go/src/cmd/go/internal/load/pkg.go:711 +0x100c
cmd/go/internal/load.(*Package).load(0x140008e6608, {0x104d03070, 0x10512c8e0}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, {0x1400026ed20, ...}, ...)
        ~/Desktop/codebase/go/src/cmd/go/internal/load/pkg.go:2029 +0x1d50
cmd/go/internal/load.loadImport({0x104d03070, 0x10512c8e0}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, 0x140002a2f10, {0x1400026ed20, ...}, ...)
        ~/Desktop/codebase/go/src/cmd/go/internal/load/pkg.go:774 +0x3d8
cmd/go/internal/load.PackagesAndErrors({0x104d03070?, 0x10512c8e0?}, {0x0, 0x0, 0x0, 0x1, 0x0, 0x0}, {0x1400011a200, 0x1, ...})
        ~/Desktop/codebase/go/src/cmd/go/internal/load/pkg.go:2955 +0x714
cmd/go/internal/list.runList({0x104d03070, 0x10512c8e0}, 0x14000132618?, {0x1400011a200, 0x1, 0x1})
        ~/Desktop/codebase/go/src/cmd/go/internal/list/list.go:616 +0xbdc
main.invoke(0x1050f5b80, {0x1400011a1f0, 0x2, 0x2})
        ~/Desktop/codebase/go/src/cmd/go/main.go:341 +0x63c
main.main()
        ~/Desktop/codebase/go/src/cmd/go/main.go:220 +0xd58

The reason why gopls act this way, I asked gopls to run a check for a go file and I did not create a go.mod file for that go file. It's under ~/Desktop/codebase/python-workspace/main.go. So gopls will try to find the module this go file belongs to going to it's parent dir and it's parent dir ..... until it reaches ~/go.mod that I accidentally put there. Once it reached to the module, gopls try to run go list which print the crash in STDOUT.

So I try the similar command go list ./... in ~ and observe very similar error.

cc @adonovan