#!stacks
"sigpanic" && "types.(*Selection).Index" && "golang.hover:+188"
Issue created by stacks.
// When hovering over a reference to a promoted struct field,
// show the implicitly selected intervening fields.
cur, ok := pgf.Cursor.FindByPos(pos, pos)
if !ok {
return protocol.Range{}, nil, fmt.Errorf("Invalid hover position, failed to get cursor")
}
if obj, ok := obj.(*types.Var); ok && obj.IsField() {
if selExpr, ok := cur.Parent().Node().(*ast.SelectorExpr); ok {
sel := pkg.TypesInfo().Selections[selExpr]
if len(sel.Index()) > 1 { <----- panics is sel is zero
@madelinekalil
This stack j9Y3kA was reported by telemetry:
crash/crashruntime.gopanic:+69,+0x167runtime.panicmem:=262,+0x197runtime.sigpanic:+9,+0x167go/types.(*Selection).Index:=137,+0xf4egolang.org/x/tools/gopls/internal/golang.hover:+188,+0xf53golang.org/x/tools/gopls/internal/golang.Hover:+4,+0xbegolang.org/x/tools/gopls/internal/server.(*server).Hover:+30,+0x3aagolang.org/x/tools/gopls/internal/protocol.serverDispatch:+335,+0xe99golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x84golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x908golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xc5golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x95runtime.goexit:+0,+0x0
golang.org/x/tools/gopls@v0.19.0-pre.2 go1.24.3 windows/amd64 vscode (1)
Dups: nagHbw cJUhUw
Comment From: adonovan
Let's cherrypick a fix for this into rc3.
Comment From: adonovan
This stack nagHbw was reported by telemetry:
crash/crashruntime.gopanic:+69,+0x153runtime.panicmem:=262,+0x2ffruntime.sigpanic:+19,+0x2ccgo/types.(*Selection).Index:=137,+0xc60golang.org/x/tools/gopls/internal/golang.hover:+188,+0xc64golang.org/x/tools/gopls/internal/golang.Hover:+4,+0x8bgolang.org/x/tools/gopls/internal/server.(*server).Hover:+30,+0x29bgolang.org/x/tools/gopls/internal/protocol.serverDispatch:+335,+0xc57golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x73golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x68fgolang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xbfgolang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x8fruntime.goexit:+0,+0x3
golang.org/x/tools/gopls@v0.19.0-pre.1 go1.24.3 darwin/arm64 other (1)
Comment From: gopherbot
Change https://go.dev/cl/680257 mentions this issue: gopls/internal/golang: add missing ,ok check
Comment From: gabyhelp
Related Issues
- x/tools/gopls: Hover: nil deref in parseDocLink #70635 (closed)
- x/tools/gopls: Hover: nil deref in golang.StdSymbolOf #70969 (closed)
- x/tools/gopls: Hover: invalid nil entry in types.Defs map #69362 (closed)
- x/tools/gopls: Hover: nil deref in typeDeclContent #74056
- x/tools/gopls: panic in hover #52211 (closed)
- x/tools/gopls: nil deref in x/telemetry/internal/counter.(*Counter).add #73890
- x/tools/gopls: "type name %q without type spec" bug in Hover (via telemetry) #64241
- x/tools/gopls: "type name %q without type spec" bug in Hover(reported by telemetry) #66314 (closed)
- x/tools/gopls: panic in mod.hoverOnModuleStatement #59077 (closed)
- x/tools/gopls: crash in work.Hover #60821 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: adonovan
This stack cJUhUw was reported by telemetry:
crash/crashruntime.gopanic:+69,+0x167runtime.panicmem:=262,+0x358runtime.sigpanic:+19,+0x328go/types.(*Selection).Index:=137,+0xf4egolang.org/x/tools/gopls/internal/golang.hover:+188,+0xf53golang.org/x/tools/gopls/internal/golang.Hover:+4,+0xbegolang.org/x/tools/gopls/internal/server.(*server).Hover:+30,+0x3aagolang.org/x/tools/gopls/internal/protocol.serverDispatch:+335,+0xe99golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x84golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x908golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xc5golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x95runtime.goexit:+0,+0x0
golang.org/x/tools/gopls@v0.19.0-pre.2 go1.24.4 linux/amd64 vscode (1)
Comment From: madelinekalil
@adonovan this just means that crashes are happening on old versions of gopls without the "missing ,ok check" fix, right?
Comment From: adonovan
Correct, this was fixed in pre.3.