Skip to content

x/tools/gopls: type checker panics when fed invalid BasicLit.Kind #76953

@adonovan

Description

@adonovan
#!stacks
"gopanic" && "go/types.(*operand).setConst:+14" && "go/types.(*Checker).basicLit:+20"

Issue created by stacks.

A BasicLit.Kind other than INT, FLOAT, IMAG, CHAR, STRING cannot result from the parser, and there are no assignments in x/tools that update the Kind field. Every place in x/tools that constructs a BasicLit fills in the Kind field to one of these values (except in gopls/internal/golang/undeclared.go, but that AST is only fed to format.Node). So this means the AST has become corrupted.

This stack -JV2Tg was reported by telemetry:

golang.org/x/tools/gopls@v0.21.0 go1.25.5 windows/amd64 gopls.client=other,vscode (1)

Use this command to reproduce the executable:
(HOME=$(mktemp -d); GOOS=windows GOARCH=amd64 GOTOOLCHAIN=go1.25.5 go install golang.org/x/tools/gopls@v0.21.0 && find $HOME/go/bin -type f)
To disassemble: go tool objdump exe | less

Metadata

Metadata

Assignees

No one assigned

    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/memory-corruption"can't happen" gopls crashes (races, unsafe, miscompile, runtime bugs, faulty HW)gopls/telemetry-wins

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions