Skip to content

x/tools/gopls/internal/mcp: symbol references tool panics in ObjectLocation after nil result from types.LookupFieldOrMethod #74904

@adonovan

Description

@adonovan
#!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)

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/telemetry-wins

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions