#!stacks
"sigpanic" && "golang.isBuiltin" && "golang.ObjectLocation" && "mcp.(*handler).symbolReferencesHandler:+32"

Issue created by stacks.

resolveSymbol may return (nil, nil) leading to a panic

func resolveSymbol(path []string, pkg *cache.Package, pgf *parsego.File) (types.Object, error) {
    ...
    switch len(path) {
    case 1:
        _, target := fileScope.LookupParent(path[0], token.NoPos)
        return target, nil <------- here
    case 2:
        switch _, obj := fileScope.LookupParent(path[0], token.NoPos); obj := obj.(type) {
        ...
        default:
            target, _, _ := types.LookupFieldOrMethod(obj.Type(), true, pkg.Types(), path[1])
            return target, nil <---------- here
        }
    target, err := resolveSymbol(path, pkg, pgf)
    if err != nil {
        return nil, err
    }

    loc, err := golang.ObjectLocation(ctx, pkg.FileSet(), snapshot, target) <---- target = nil; panics in isBuiltin

This stack hZ-M9w was reported by telemetry:

golang.org/x/tools/gopls@v0.20.0 go1.24.5 darwin/arm64 neovim,other (1)
golang.org/x/tools/gopls@v0.20.0-pre.1 go1.24.5 darwin/arm64 other (1)

Comment From: ANAS727189

Raised a pr for this issue on gerrit

Comment From: gopherbot

Change https://go.dev/cl/697315 mentions this issue: mcp: fix panic in symbolReferencesHandler on nil types.Object