#!stacks
"sigpanic" && "golang.typeDeclContent" && "findRhsTypeDecl"
Issue created by stacks.
// findRhsTypeDecl finds an alias's rhs type and returns its declaration.
// The rhs of an alias might be an alias as well, but we feel this is a rare case.
// It returns an empty string if the given obj is not an alias.
func findRhsTypeDecl(ctx context.Context, snapshot *cache.Snapshot, pkg *cache.Package, obj types.Object) (string, error) {
if alias, ok := obj.Type().(*types.Alias); ok {
// we choose Rhs instead of types.Unalias to make the connection between original alias
// and the corresponding aliased type clearer.
// types.Unalias brings confusion because it breaks the connection from A to C given
// the alias chain like 'type ( A = B; B =C ; )' except we show all transitive alias
// from start to the end. As it's rare, we don't do so.
t := alias.Rhs()
switch o := t.(type) {
case *types.Named:
obj = o.Obj()
declPGF1, declPos1, _ := parseFull(ctx, snapshot, pkg.FileSet(), obj.Pos()) <------ missing error check
realTypeDecl, _, err := typeDeclContent(declPGF1, declPos1, obj) <---- panics if declPGF1 is nil
return realTypeDecl, err
}
}
return "", nil
}
@xieyuschen
This stack 33hzqg
was reported by telemetry:
crash/crash
runtime.gopanic:+69,+0x153
runtime.panicmem:=262,+0x2ff
runtime.sigpanic:+19,+0x2cc
golang.org/x/tools/gopls/internal/golang.typeDeclContent:+1,+0x2c
golang.org/x/tools/gopls/internal/golang.findRhsTypeDecl:+12,+0xe3
golang.org/x/tools/gopls/internal/golang.hover:+389,+0x16f7
golang.org/x/tools/gopls/internal/golang.Hover:+4,+0x8b
golang.org/x/tools/gopls/internal/server.(*server).Hover:+30,+0x29b
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+335,+0xc57
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x73
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x68f
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xbf
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x8f
runtime.goexit:+0,+0x3
golang.org/x/tools/gopls@v0.19.0-pre.2 go1.24.3 darwin/arm64 other (1)
Comment From: adonovan
Let's cherrypick a fix for this into rc3.
Comment From: gopherbot
Change https://go.dev/cl/680296 mentions this issue: gopls/internal/golang: add missing err check
Comment From: gabyhelp
Related Issues
- x/tools/gopls: Hover: invalid nil entry in types.Defs map #69362 (closed)
- x/tools/gopls: Hover: nil deref in golang.StdSymbolOf #70969 (closed)
- x/tools/gopls: Hover: nil deref in parseDocLink #70635 (closed)
- x/tools/gopls: Hover: nil deref using zero types.Selection #74058
- x/tools/gopls: nil Signature (?) deref in Completion #70634 (closed)
- x/tools/gopls: Completion: nil deref in expectedCompositeLiteralType #72136 (closed)
- go/types: panic("t.fromRHS = %s, typ = %s") in setDefType #71029 (closed)
- x/tools/gopls: Rename: crash due to Info.Defs[id]=nil bug in checkStructField #70968 (closed)
- x/tools/gopls: Completion: failed type assertion in completer.item #71044 (closed)
- x/tools/gopls: impossible nil panic in reflect.ValueOf #73853
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)