Fix panic on bare PkgName identifier references#261
Merged
Merged
Conversation
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.
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.
eseliger
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
var _ = sort(afterimport "sort") is syntactically valid Go but ill-typed; the compiler rejects it withuse of package sort not in selector. The parser still accepts it and the type checker, run in best-effort mode bypackages.Load, still recordsinfo.Uses[sort] = *types.PkgName.Well-typed code always wraps such uses in a
*ast.SelectorExprwhich the visitor handles separately; a bare ident slips past it intoGetSymbolOfObjectand trips itsshould never lookup PkgName ...assertion.Skip bare
*types.PkgNamereferences in the file visitor so ill-typed source no longer crashes the indexer.