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

x/tools/gopls: runtime error: index out of range [495] #61670

Closed
sylr opened this issue Jul 31, 2023 · 7 comments
Closed

x/tools/gopls: runtime error: index out of range [495] #61670

sylr opened this issue Jul 31, 2023 · 7 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@sylr
Copy link

sylr commented Jul 31, 2023

gopls version

Build info
----------
golang.org/x/tools/gopls v0.13.0
    golang.org/x/tools/gopls@v0.13.0 h1:ZUvkm53dJpJ9sUXWtgH39rD53JyQ9/vwB1cpI7swnGo=
    github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/go-cmp@v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp@v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
    golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/mod@v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
    golang.org/x/sync@v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
    golang.org/x/sys@v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
    golang.org/x/text@v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
    golang.org/x/tools@v0.11.1-0.20230727183555-65b14ec44dc9 h1:KyJgiheQsNju4tb8D6MzAlWqI0YS5LbPyDgitUfKCZg=
    golang.org/x/vuln@v0.0.0-20230110180137-6ad3e3d07815 h1:A9kONVi4+AnuOr1dopsibH6hLi1Huy54cbeJxnq4vmU=
    honnef.co/go/tools@v0.4.2 h1:6qXr+R5w+ktL5UkwEbPp+fEvfyoMPche6GkOpGHZcLc=
    mvdan.cc/gofumpt@v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.20.6

go env

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/sylvain/Library/Caches/go-build"
GOENV="/Users/sylvain/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/sylvain/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/sylvain/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.20.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.6/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.6"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/Users/sylvain/git/<redacted>/go.mod"
GOWORK="/Users/sylvain/git/<redacted>/go.work"
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jq/lq71x93965l422wp3h87r1lr0000gn/T/go-build696922228=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Upgraded from something pre v0.13.0 to v0.13.0 and got errors.

What did you expect to see?

No errors.

What did you see instead?

could not import github.com/company/project (import failed for "github.com/company/project": internal error while importing "github.com/company/project" (runtime error: index out of range [495] with length 16); please report an issue)compilerBrokenImport

Editor and settings

VSCode / Go

Logs

[Info  - 16:09:52] 2023/07/31 16:09:52 go info for /Users/sylvain/git/<redacted>
(go dir /Users/sylvain/git/<redacted>)
(go version go version go1.20.6 darwin/arm64)
(valid build configuration = true)
(build flags: [-tags sql_scanner,goexperiment.arenas])
(selected go env: [GO111MODULE=, GOCACHE=/Users/sylvain/Library/Caches/go-build, GOFLAGS=, GOMODCACHE=/Users/sylvain/go/pkg/mod, GOPATH=/Users/sylvain/go, GOPRIVATE=, GOROOT=/opt/homebrew/Cellar/go/1.20.6/libexec, GOWORK=/Users/sylvain/git/<redacted>/go.work])


[Info  - 16:09:52] 2023/07/31 16:09:52 go/packages.Load #1
	snapshot=0
	directory=file:///Users/sylvain/git/<redacted>
	query=[/Users/sylvain/git/<redacted>/... /Users/sylvain/git/btree/... /Users/sylvain/git/fixed/... /Users/sylvain/git/go-timeutils/... /Users/sylvain/git/pgx/... builtin]
	packages=106

[Info  - 16:09:52] 2023/07/31 16:09:52 go/packages.Load #1: updating metadata for 376 packages

[Error - 16:09:53] 2023/07/31 16:09:53 computing the shared import graph: import failed for "github.com/company/project": internal error while importing "github.com/company/project" (runtime error: index out of range [495] with length 16); please report an issue

[Error - 16:09:58] 2023/07/31 16:09:58 computing the shared import graph: import failed for "github.com/company/project": internal error while importing "github.com/company/project" (runtime error: index out of range [495] with length 16); please report an issue
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jul 31, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jul 31, 2023
@findleyr
Copy link
Contributor

@sylr this will be hard to track down without a repro. If this is closed-source, could you please do the following to get us a real stack trace?

git clone https://go.googlesource.com/tools
cd tools
<edit internal/gcimporter/gcimporter.go to set debug=true>
cd gopls
go install

Running gopls with the resulting binary will crash during import, and reveal the real problem.

@sylr
Copy link
Author

sylr commented Jul 31, 2023

[Info  - 16:25:48] 2023/07/31 16:25:48 go info for /Users/sylvain/git/<redacted>
(go dir /Users/sylvain/git/<redacted>)
(go version go version go1.20.6 darwin/arm64)
(valid build configuration = true)
(build flags: [-tags sql_scanner,goexperiment.arenas])
(selected go env: [GO111MODULE=, GOCACHE=/Users/sylvain/Library/Caches/go-build, GOFLAGS=, GOMODCACHE=/Users/sylvain/go/pkg/mod, GOPATH=/Users/sylvain/go, GOPRIVATE=, GOROOT=/opt/homebrew/Cellar/go/1.20.6/libexec, GOWORK=/Users/sylvain/git/<redacted>/go.work])


[Info  - 16:25:49] 2023/07/31 16:25:49 go/packages.Load #1
	snapshot=0
	directory=file:///Users/sylvain/git/<redacted>
	query=[/Users/sylvain/git/<redacted>/... /Users/sylvain/git/btree/... /Users/sylvain/git/fixed/... /Users/sylvain/git/go-timeutils/... /Users/sylvain/git/pgx/... builtin]
	packages=106

[Info  - 16:25:49] 2023/07/31 16:25:49 go/packages.Load #1: updating metadata for 376 packages

panic: runtime error: index out of range [495] with length 16

goroutine 12384 [running]:
golang.org/x/tools/internal/gcimporter.(*iimporter).fileAt(0x14010a1cf38?, 0x102a89b80?)
	/tmp/tools/internal/gcimporter/iimport.go:433 +0x168
golang.org/x/tools/internal/gcimporter.(*importReader).posv2(0x140134ba9c0)
	/tmp/tools/internal/gcimporter/iimport.go:819 +0x48
golang.org/x/tools/internal/gcimporter.(*importReader).pos(0x140134ba9c0?)
	/tmp/tools/internal/gcimporter/iimport.go:776 +0x98
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140134ba9c0, 0x1401348ccb0)
	/tmp/tools/internal/gcimporter/iimport.go:881 +0xeec
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x140001ebb80, 0x8d9, 0x1401348ccb0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).obj(0x140134ba960, {0x1400a37bf38, 0x13})
	/tmp/tools/internal/gcimporter/iimport.go:572 +0x874
golang.org/x/tools/internal/gcimporter.(*iimporter).doDecl(0x140001ebb80, 0x14010359860, {0x1400a37bf38, 0x13})
	/tmp/tools/internal/gcimporter/iimport.go:414 +0x1e0
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140134ba900, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:852 +0xd4
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x140001ebb80, 0x7ca, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).typ(0x140134ba8a0)
	/tmp/tools/internal/gcimporter/iimport.go:824 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140134ba8a0, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:855 +0x174
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x140001ebb80, 0x7ce, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).typ(0x140134ba660)
	/tmp/tools/internal/gcimporter/iimport.go:824 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140134ba660, 0x1401348cc40)
	/tmp/tools/internal/gcimporter/iimport.go:883 +0xf0c
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x140001ebb80, 0x7d1, 0x1401348cc40)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).obj(0x140134ba5a0, {0x140080cc010, 0xd})
	/tmp/tools/internal/gcimporter/iimport.go:572 +0x874
golang.org/x/tools/internal/gcimporter.(*iimporter).doDecl(0x140001ebb80, 0x14010359860, {0x140080cc010, 0xd})
	/tmp/tools/internal/gcimporter/iimport.go:414 +0x1e0
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140134ba540, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:852 +0xd4
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x140001ebb80, 0x37, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).typ(0x140134ba4e0)
	/tmp/tools/internal/gcimporter/iimport.go:824 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140134ba4e0, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:855 +0x174
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x140001ebb80, 0x3a, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).typ(0x140134ba480)
	/tmp/tools/internal/gcimporter/iimport.go:824 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).param(0x140134ba480)
	/tmp/tools/internal/gcimporter/iimport.go:1043 +0x40
golang.org/x/tools/internal/gcimporter.(*importReader).paramList(0x1032f5700?)
	/tmp/tools/internal/gcimporter/iimport.go:1035 +0x68
golang.org/x/tools/internal/gcimporter.(*importReader).signature(0x140134ba480?, 0x0?, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0})
	/tmp/tools/internal/gcimporter/iimport.go:1012 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140134ba480, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:868 +0x4a8
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x140001ebb80, 0x3e, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).typ(0x140134ba2a0)
	/tmp/tools/internal/gcimporter/iimport.go:824 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140134ba2a0, 0x1401348cbd0)
	/tmp/tools/internal/gcimporter/iimport.go:883 +0xf0c
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x140001ebb80, 0xbc, 0x1401348cbd0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).obj(0x140134ba1e0, {0x14007fbff70, 0xc})
	/tmp/tools/internal/gcimporter/iimport.go:572 +0x874
golang.org/x/tools/internal/gcimporter.(*iimporter).doDecl(0x140001ebb80, 0x14010359860, {0x14007fbff70, 0xc})
	/tmp/tools/internal/gcimporter/iimport.go:414 +0x1e0
golang.org/x/tools/internal/gcimporter.iimportCommon(0x1401030f740, 0x14010a1f478, {0x14005614000, 0x3a4c, 0x4000}, 0x0, {0x140003e0c40, 0x1a}, 0x1, 0x1033fac28)
	/tmp/tools/internal/gcimporter/iimport.go:311 +0xe4c
golang.org/x/tools/internal/gcimporter.IImportShallow(0x140003e0c40?, 0x1a?, {0x14005614000?, 0x6?, 0x140171ebd70?}, {0x140003e0c40?, 0x140103c73b8?}, 0x1027b4a98?)
	/tmp/tools/internal/gcimporter/iexport.go:68 +0x38
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).importPackage(0x1400da91aa0, {0x1034069a8, 0x140171eb980}, 0x14000c89560, {0x14005614000, 0x3a4c, 0x4000})
	/tmp/tools/gopls/internal/lsp/cache/check.go:585 +0x200
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).getImportPackage(0x1400da91aa0, {0x1034069a8, 0x140171eb980}, {0x140003e0c40, 0x1a})
	/tmp/tools/gopls/internal/lsp/cache/check.go:464 +0x5f8
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).importPackage.func1({0x140132c3a20, 0x6, 0x14007fbff20?})
	/tmp/tools/gopls/internal/lsp/cache/check.go:561 +0x140
golang.org/x/tools/internal/gcimporter.iimportCommon(0x1401030f740, 0x140103c7d88, {0x1400f865100, 0x188d, 0x1b00}, 0x0, {0x140000da960, 0x25}, 0x1, 0x1033fac28)
	/tmp/tools/internal/gcimporter/iimport.go:256 +0x690
golang.org/x/tools/internal/gcimporter.IImportShallow(0x140000da960?, 0x25?, {0x1400f865100?, 0x7?, 0x140171eb8f0?}, {0x140000da960?, 0x1400b2cfcc8?}, 0x1028214e0?)
	/tmp/tools/internal/gcimporter/iexport.go:68 +0x38
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).importPackage(0x1400da91aa0, {0x1034069a8, 0x14017058060}, 0x14000cfc240, {0x1400f865100, 0x188d, 0x1b00})
	/tmp/tools/gopls/internal/lsp/cache/check.go:585 +0x200
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).getImportPackage(0x1400da91aa0, {0x1034069a8, 0x14017058060}, {0x140000da960, 0x25})
	/tmp/tools/gopls/internal/lsp/cache/check.go:464 +0x5f8
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).forEachPackageInternal.func1()
	/tmp/tools/gopls/internal/lsp/cache/check.go:386 +0x30
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/Users/sylvain/go/pkg/mod/golang.org/x/sync@v0.3.0/errgroup/errgroup.go:75 +0x5c
created by golang.org/x/sync/errgroup.(*Group).Go
	/Users/sylvain/go/pkg/mod/golang.org/x/sync@v0.3.0/errgroup/errgroup.go:72 +0xa0
[Info  - 16:26:48] 
true
[Info  - 16:26:48] 2023/07/31 16:26:48 go info for /Users/sylvain/git/<redacted>
(go dir /Users/sylvain/git/<redacted>)
(go version go version go1.20.6 darwin/arm64)
(valid build configuration = true)
(build flags: [-tags sql_scanner,goexperiment.arenas])
(selected go env: [GO111MODULE=, GOCACHE=/Users/sylvain/Library/Caches/go-build, GOFLAGS=, GOMODCACHE=/Users/sylvain/go/pkg/mod, GOPATH=/Users/sylvain/go, GOPRIVATE=, GOROOT=/opt/homebrew/Cellar/go/1.20.6/libexec, GOWORK=/Users/sylvain/git/<redacted>/go.work])


[Info  - 16:26:48] 2023/07/31 16:26:48 go/packages.Load #1
	snapshot=0
	directory=file:///Users/sylvain/git/<redacted>
	query=[/Users/sylvain/git/<redacted>/... /Users/sylvain/git/btree/... /Users/sylvain/git/fixed/... /Users/sylvain/git/go-timeutils/... /Users/sylvain/git/pgx/... builtin]
	packages=106

[Info  - 16:26:48] 2023/07/31 16:26:48 go/packages.Load #1: updating metadata for 376 packages

panic: runtime error: index out of range [495] with length 16

goroutine 3283 [running]:
golang.org/x/tools/internal/gcimporter.(*iimporter).fileAt(0x1400406d848?, 0x100455b80?)
	/tmp/tools/internal/gcimporter/iimport.go:433 +0x168
golang.org/x/tools/internal/gcimporter.(*importReader).posv2(0x140048cdbc0)
	/tmp/tools/internal/gcimporter/iimport.go:819 +0x48
golang.org/x/tools/internal/gcimporter.(*importReader).pos(0x140048cdbc0?)
	/tmp/tools/internal/gcimporter/iimport.go:776 +0x98
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140048cdbc0, 0x1400489d110)
	/tmp/tools/internal/gcimporter/iimport.go:881 +0xeec
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x14002f71a40, 0x8d9, 0x1400489d110)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).obj(0x140048cdb60, {0x140002c5da0, 0x13})
	/tmp/tools/internal/gcimporter/iimport.go:572 +0x874
golang.org/x/tools/internal/gcimporter.(*iimporter).doDecl(0x14002f71a40, 0x1400443a1e0, {0x140002c5da0, 0x13})
	/tmp/tools/internal/gcimporter/iimport.go:414 +0x1e0
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140048cdb00, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:852 +0xd4
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x14002f71a40, 0x7ca, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).typ(0x140048cdaa0)
	/tmp/tools/internal/gcimporter/iimport.go:824 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140048cdaa0, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:855 +0x174
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x14002f71a40, 0x7ce, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).typ(0x140048cd860)
	/tmp/tools/internal/gcimporter/iimport.go:824 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140048cd860, 0x1400489d0a0)
	/tmp/tools/internal/gcimporter/iimport.go:883 +0xf0c
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x14002f71a40, 0x7d1, 0x1400489d0a0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).obj(0x140048cd7a0, {0x14004356fd0, 0xd})
	/tmp/tools/internal/gcimporter/iimport.go:572 +0x874
golang.org/x/tools/internal/gcimporter.(*iimporter).doDecl(0x14002f71a40, 0x1400443a1e0, {0x14004356fd0, 0xd})
	/tmp/tools/internal/gcimporter/iimport.go:414 +0x1e0
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140048cd740, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:852 +0xd4
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x14002f71a40, 0x37, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).typ(0x140048cd6e0)
	/tmp/tools/internal/gcimporter/iimport.go:824 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140048cd6e0, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:855 +0x174
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x14002f71a40, 0x3a, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).typ(0x140048cd680)
	/tmp/tools/internal/gcimporter/iimport.go:824 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).param(0x140048cd680)
	/tmp/tools/internal/gcimporter/iimport.go:1043 +0x40
golang.org/x/tools/internal/gcimporter.(*importReader).paramList(0x100cc1700?)
	/tmp/tools/internal/gcimporter/iimport.go:1035 +0x68
golang.org/x/tools/internal/gcimporter.(*importReader).signature(0x140048cd680?, 0x140000320a0?, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0})
	/tmp/tools/internal/gcimporter/iimport.go:1012 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140048cd680, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:868 +0x4a8
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x14002f71a40, 0x3e, 0x0)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).typ(0x140048cd4a0)
	/tmp/tools/internal/gcimporter/iimport.go:824 +0x3c
golang.org/x/tools/internal/gcimporter.(*importReader).doType(0x140048cd4a0, 0x1400489d030)
	/tmp/tools/internal/gcimporter/iimport.go:883 +0xf0c
golang.org/x/tools/internal/gcimporter.(*iimporter).typAt(0x14002f71a40, 0xbc, 0x1400489d030)
	/tmp/tools/internal/gcimporter/iimport.go:501 +0x194
golang.org/x/tools/internal/gcimporter.(*importReader).obj(0x140048cd3e0, {0x14004356f20, 0xc})
	/tmp/tools/internal/gcimporter/iimport.go:572 +0x874
golang.org/x/tools/internal/gcimporter.(*iimporter).doDecl(0x14002f71a40, 0x1400443a1e0, {0x14004356f20, 0xc})
	/tmp/tools/internal/gcimporter/iimport.go:414 +0x1e0
golang.org/x/tools/internal/gcimporter.iimportCommon(0x140031fcd00, 0x1400406fd88, {0x14004452000, 0x3a4c, 0x3a4d}, 0x0, {0x1400041cfa0, 0x1a}, 0x1, 0x100dc6c28)
	/tmp/tools/internal/gcimporter/iimport.go:311 +0xe4c
golang.org/x/tools/internal/gcimporter.IImportShallow(0x1400041cfa0?, 0x1a?, {0x14004452000?, 0x6?, 0x1400444e5d0?}, {0x1400041cfa0?, 0x20?}, 0xde64fe2eab6611b9?)
	/tmp/tools/internal/gcimporter/iexport.go:68 +0x38
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).importPackage(0x14000358540, {0x100dd29a8, 0x140031a0360}, 0x14000add9e0, {0x14004452000, 0x3a4c, 0x3a4d})
	/tmp/tools/gopls/internal/lsp/cache/check.go:585 +0x200
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).getImportPackage(0x14000358540, {0x100dd29a8, 0x140031a0360}, {0x1400041cfa0, 0x1a})
	/tmp/tools/gopls/internal/lsp/cache/check.go:464 +0x5f8
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).forEachPackageInternal.func1()
	/tmp/tools/gopls/internal/lsp/cache/check.go:386 +0x30
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/Users/sylvain/go/pkg/mod/golang.org/x/sync@v0.3.0/errgroup/errgroup.go:75 +0x5c
created by golang.org/x/sync/errgroup.(*Group).Go
	/Users/sylvain/go/pkg/mod/golang.org/x/sync@v0.3.0/errgroup/errgroup.go:72 +0xa0
[Error - 16:26:48] Client gopls: connection to server is erroring. Shutting down server.
[Error - 16:26:48] Request textDocument/codeLens failed.
  Message: write EPIPE
  Code: -32099 
[Error - 16:26:48] Connection to server got closed. Server will not be restarted.
[Error - 16:26:48] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 16:26:48] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 

@findleyr
Copy link
Contributor

findleyr commented Jul 31, 2023

Thank you very much @sylr.

Can you please try patching the following CL, and check if it fixes the bug?

git fetch https://go.googlesource.com/tools refs/changes/55/514355/2 && git checkout FETCH_HEAD<and then install gopls from the gopls dir again>

After doing that, if it doesn't fix the problem could you try nuking your gopls file cache? (it is likely under ~/.cache/gopls, and you can simply delete it). That will rule out some sort of corruption.

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.13.1 Jul 31, 2023
@gopherbot
Copy link

Change https://go.dev/cl/514355 mentions this issue: internal/gcimporter: add a missing return if objectpath fails

@findleyr
Copy link
Contributor

@sylr could I ask you to do one more thing? The codepath that was buggy was supposed to only be hit in "impossible" scenarios. The buggy logic was related to the fallback behavior.

If you could do the following, it would help us find the underlying bug in our export algorithm:

In gopls/main.go, add the following to the main function:

	bug.PanicOnBugs = true

(and then add the missing import of "golang.org/x/tools/gopls/internal/bug", or have gopls do it for you).

Then your gopls should be broken again, but the error message will tell us which struct field could not be found by the objectpath algorithm. Without sharing the code, if you could describe to us the nature of that field (where is it defined, is it embedded, is it part of a type declaration, etc), that would be very helpful.

@findleyr
Copy link
Contributor

Actually, I have found one such case, when promoting an instantiated field from another package:

// package a
type A[P any] struct{ F P }

// package b
type B[P any] a.A[int]

I'd be curious if the problematic object in your repo follows a similar pattern.

@Splizard
Copy link

Splizard commented Aug 1, 2023

Can reproduce this sort of problem with exported embedded fields for a type definition. Variants of this pattern:

package lib

type A[T any] struct {
 privateA[T]
}

type privateA[T any] struct {}
func (privateA[T]) ExportedMethod() {}
package lib2

import "lib"

type A lib.A[int]
package main

import "lib2" // unexpected kind tag in "lib2": 57

type T lib2.A

func main() {
    var zero T
    zero.ExportedMethod()
}

I've also seen the "index out of range" issue in a real codebase, this example is what I managed to reduce it to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants