Skip to content

Fix panic on bare PkgName identifier references#261

Merged
jupblb merged 3 commits into
mainfrom
michal/bug2
May 20, 2026
Merged

Fix panic on bare PkgName identifier references#261
jupblb merged 3 commits into
mainfrom
michal/bug2

Conversation

@jupblb
Copy link
Copy Markdown
Collaborator

@jupblb jupblb commented May 20, 2026

var _ = sort (after import "sort") is syntactically valid Go but ill-typed; the compiler rejects it with use of package sort not in selector. The parser still accepts it and the type checker, run in best-effort mode by packages.Load, still records info.Uses[sort] = *types.PkgName.

Well-typed code always wraps such uses in a *ast.SelectorExpr which the visitor handles separately; a bare ident slips past it into GetSymbolOfObject and trips its should never lookup PkgName ... assertion.

Skip bare *types.PkgName references in the file visitor so ill-typed source no longer crashes the indexer.

A bare *ast.Ident whose info.Uses entry is a *types.PkgName (e.g.
'var _ = sort' after 'import "sort"') is malformed Go, but the parser
and type checker still record the use. Well-formed code routes such
references through the *ast.SelectorExpr handler, but bare idents
slipped through to GetSymbolOfObject and tripped its
'should never lookup PkgName ...' assertion.

Skip bare *types.PkgName references in the file visitor so malformed
source no longer crashes the indexer.
@jupblb jupblb requested review from emidoots, eseliger and trly May 20, 2026 11:59
@jupblb jupblb enabled auto-merge (squash) May 20, 2026 12:00
pr261's repro keeps an intentionally-unused 'sort' import to reproduce
the bare PkgName panic. goimports would strip the import and break the
repro, so skip the directory the same way snapshots/output is skipped.
@jupblb jupblb merged commit 1645259 into main May 20, 2026
14 checks passed
@jupblb jupblb deleted the michal/bug2 branch May 20, 2026 12:14
@jupblb jupblb mentioned this pull request May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants