Skip to content

x/tools/gopls: Hover: nil deref using zero types.Selection #74058

@adonovan

Description

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

golang.org/x/tools/[email protected] go1.24.3 windows/amd64 vscode (1)

Dups: nagHbw cJUhUw

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.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

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions