#!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:

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

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)