Skip to content

fix: handle XGo AST extension nodes consistently#2806

Merged
xushiwei merged 1 commit into
goplus:mainfrom
aofei:ast-extension-coverage
Jul 1, 2026
Merged

fix: handle XGo AST extension nodes consistently#2806
xushiwei merged 1 commit into
goplus:mainfrom
aofei:ast-extension-coverage

Conversation

@aofei

@aofei aofei commented Jun 29, 2026

Copy link
Copy Markdown
Member

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

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.00000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.26%. Comparing base (d855433) to head (76bcb85).

Files with missing lines Patch % Lines
x/format/stmt_expr_or_type.go 95.23% 3 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread x/format/stmt_expr_or_type.go
Comment thread x/format/gopstyle.go
Comment thread x/format/stmt_expr_or_type.go
@aofei aofei force-pushed the ast-extension-coverage branch 3 times, most recently from 164ff1e to a774d26 Compare June 30, 2026 08:31
@aofei aofei marked this pull request as ready for review June 30, 2026 08:35

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go formatFile: the decl switch handles only *ast.FuncDecl and *ast.GenDecl; *ast.OverloadFuncDecl falls through silently. Its Funcs may contain *ast.SelectorExpr referencing an imported package (e.g. func F = (pkg.Method)), so that import would not be marked used.
  • x/format/stmt_expr_or_type.go formatForStmt: skips v.Post, while ast.Walk visits it.
  • x/format/stmt_expr_or_type.go formatFuncType: skips t.TypeParams, while ast.Walk visits 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.

Comment thread ast/walk.go Outdated
@aofei aofei force-pushed the ast-extension-coverage branch from a774d26 to 5b141a5 Compare June 30, 2026 09:14
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>
@aofei aofei force-pushed the ast-extension-coverage branch from 5b141a5 to 76bcb85 Compare June 30, 2026 09:48
@xushiwei xushiwei merged commit 9d81843 into goplus:main Jul 1, 2026
11 checks passed
@aofei aofei deleted the ast-extension-coverage branch July 1, 2026 06:01
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