Skip to content

x/tools/gopls: Completion: nil deref panic in addFieldItems #72828

@adonovan

Description

@adonovan
#!stacks
"sigpanic" && "completion.(*completer).addFieldItems:+5"

Issue created by stacks.

// adds struct fields, interface methods, function declaration fields to completion
func (c *completer) addFieldItems(fields *ast.FieldList) {
	if fields == nil {
		return
	}

	cursor := c.surrounding.cursor <--- panic

From the calling context, it's clear that c is non-nil, so c.surrounding must be nil. This can happen if the various setSurrounding* functions are not called or return early. The fix is to make the panicking statement defensive.

This stack tANNhQ was reported by telemetry:

golang.org/x/tools/gopls@v0.18.1 go1.23.5 darwin/arm64 neovim,vscode (1)

Dups: k4iQ0g 6sJfxg

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