fix: handle XGo AST extension nodes consistently#2806
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2806 +/- ##
==========================================
+ Coverage 94.22% 94.26% +0.04%
==========================================
Files 32 32
Lines 10454 10556 +102
==========================================
+ Hits 9850 9951 +101
+ Misses 431 430 -1
- Partials 173 175 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request adds support for several new AST nodes and constructs (such as EnumType, MatrixLit, ElemEllipsis, DomainTextLitEx, and decorators) across the AST filtering, walking, parsing, and formatting packages, along with comprehensive unit tests. The review feedback focuses on adding defensive nil checks in the formatting code to prevent potential nil pointer dereferences when processing DomainTextLitEx, decorators, and EnumType specifications.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
164ff1e to
a774d26
Compare
There was a problem hiding this comment.
Review summary
Solid, well-targeted change. The core fix is correct: ast.Walk now traverses the XGo-specific extension nodes (DomainTextLit args, ValueSpec.Tag, MatrixLit, ElemEllipsis), parser.checkExpr accepts MatrixLit, ast/filter.go filters EnumType specs, and x/format recurses through the matching node set so imports are kept/removed based on actual use. The ForPhrase reorder to source order in walk.go is consistent with formatForPhrase. Build and go test ./ast/ ./parser/ ./x/format/ pass, and the added unit tests cover the new traversal paths.
A few non-blocking notes below — one inline, and some pre-existing gaps surfaced by this consistency audit.
Pre-existing x/format coverage gaps (optional follow-ups)
This PR audits manually-maintained AST consumers, which surfaces a few spots x/format still does not cover. None are regressions from this PR, but they belong to the same class of "drop a used import" risk the PR is closing:
x/format/gopstyle.goformatFile: the declswitchhandles only*ast.FuncDecland*ast.GenDecl;*ast.OverloadFuncDeclfalls through silently. ItsFuncsmay contain*ast.SelectorExprreferencing an imported package (e.g.func F = (pkg.Method)), so that import would not be marked used.x/format/stmt_expr_or_type.goformatForStmt: skipsv.Post, whileast.Walkvisits it.x/format/stmt_expr_or_type.goformatFuncType: skipst.TypeParams, whileast.Walkvisits them (e.g.func f[T fmt.Stringer]()).
Minor doc note (pre-existing, out of scope)
CLAUDE.md line 22 ("Printer shares test cases with parser - do NOT create separate test files in printer/_testdata/") is inaccurate: printer/_testdata/ exists with its own cases and TestFromTestdata runs them separately from TestFromParse. Not changed by this PR, but it sits right beside the lines you edited, so worth fixing while you're here.
a774d26 to
5b141a5
Compare
Shared AST utilities, expression validation, and smart formatting had not kept pace with XGo-specific syntax nodes added over time. Matrix literal parsing fixes in goplus#2755 exposed one of those gaps, where valid matrix nodes could reach traversal and formatting paths that did not handle them consistently. Walk embedded expressions in domain text literals, class field tags, matrix literals, and element ellipses, and keep for-phrase traversal in source order. Preserve exported enum values in `FileExports`. Allow matrix literals in parser expression validation and recurse through XGo expression, type, decorator, receiver, and tag nodes during smart formatting so imports are kept or removed based on actual use. Updates goplus#2755 Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
5b141a5 to
76bcb85
Compare
Shared AST utilities, expression validation, and smart formatting had not kept pace with XGo-specific syntax nodes added over time. Matrix literal parsing fixes in #2755 exposed one of those gaps, where valid matrix nodes could reach traversal and formatting paths that did not handle them consistently.
Walk embedded expressions in domain text literals, class field tags, matrix literals, and element ellipses, and keep for-phrase traversal in source order. Preserve exported enum values in
FileExports.Allow matrix literals in parser expression validation and recurse through XGo expression, type, decorator, receiver, and tag nodes during smart formatting so imports are kept or removed based on actual use.
Updates #2755