Skip to content

fix!: correct postfix cast and unary precedence - #38

Merged
exKAZUu merged 1 commit into
mainfrom
fix/postfix-cast-precedence
Oct 22, 2026
Merged

exKAZUu merged 1 commit into
mainfrom
fix/postfix-cast-precedence

Conversation

@exKAZUu

@exKAZUu exKAZUu commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Why

(Object) value++ parses as an update of a cast, and -value++ parses as an update of a unary result. This silently misrepresents valid Java expression nesting. The compiler-checked fixture exposes eleven incorrect structures among twenty methods.

This follows the precedence fix in grammar-orchard/tree-sitter-java-orchard commit 03fc6cd3. Its exact patch corrects the ordinary cases but introduces errors for valid intersection postfix casts; a shared postfix-only rule covers those too.

Requirements

required: Improve the forked grammar repositories, excluding CSS and Markdown, as much as possible; backward compatibility may be ignored.
required: Review fork issues and major upstream issues, PRs and recent commits; check target PRs for duplicates and use a dedicated PR from latest main for each eligible origin.
required: Run review-booster and complete-pr concurrently, then release the changes, and continue the remaining eligible items.
required: Expose the actual nesting of valid Java expressions to structural parser queries.
chosen: Resolve the postfix/cast precedence origin from grammar-orchard/tree-sitter-java-orchard commit 03fc6cd3 separately from the intersection-operand origin already released in 8.0.3.
chosen: Restrict update operands to primary expressions and retain existing public node names; this prevents casts and unary results from becoming update targets while preserving variable, field, array and parenthesized targets.
chosen: Share a postfix-only hidden rule aliased to update_expression inside intersection casts; the exact upstream patch introduced errors for two compiler-valid intersection updates, and admitting prefix updates there would violate the Java cast syntax.
chosen: Publish a major release because update_expression.children narrows from expression to primary_expression and corrected nesting changes structural query expectations; no compatibility shim is needed.

Customer Summary

Postfix increments and decrements stay inside surrounding casts and unary expressions. This is a major release: update operands are primary expressions, and queries expecting cast or unary nodes directly under an update must follow the corrected nesting.

Technical Summary

Use right associativity for casts and updates and restrict update operands to primary expressions. Share postfix parsing through a hidden rule aliased to the existing update_expression in intersection-cast values, preserving its public name while excluding prefix updates there. Regenerate the parser and schema. The only schema change is update_expression.children: expression becomes primary_expression.

The corpus covers twenty complete methods with primitive/reference/intersection casts, prefix/postfix operators, nested casts, unary operators, parentheses, fields and arrays. The API regression checks query captures through the alias and ordinary updates. README examples use grammar major 9 with the same tested runtime 9.

Testing

  • Official JDK 27.0.1 compiled the twenty-method fixture with empty diagnostics; all twenty final parser structures match the required nesting.
  • Canonical generation passed 163 native/Wasm corpus cases without warnings. bun run verify passed with no code-gauge findings; 69 focused tests in 13 files and Rust unit/doc tests passed.
  • All 163 corpus cases passed 100 incremental fuzz iterations with up to 10 edits, explicitly logged start seed 1.
  • Twenty method tags and eight edit/undo states passed full tree/field/span/custom-and-shipped-query comparisons, including removing and restoring a postfix operator.
  • 32 control programs, 240 whitespace full trees and six CST/query controls exactly match actual 8.0.3. Sixteen additional unary methods match exactly; the seventeenth has only the intended -x++ reparenting, with identical token metadata and all 17 methods' shipped captures unchanged.
  • Full PR CI passed, including browser, Rust, Linux, both macOS variants and robustness fuzzing.

Notes

The scope is expression structure. Variable assignability and type checking remain the Java compiler's responsibility. Scoped control comparisons do not claim universal parser parity.

Keep postfix updates inside surrounding casts and unary expressions.
Reuse a postfix-only rule in intersection casts so valid operands retain
their public update node and query structure.

BREAKING CHANGE: update_expression children are primary_expression rather
than expression, and postfix update nesting follows the Java operand.

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@exKAZUu exKAZUu self-assigned this Oct 22, 2026
@exKAZUu
exKAZUu merged commit 99b94aa into main Oct 22, 2026
10 checks passed
@exKAZUu
exKAZUu deleted the fix/postfix-cast-precedence branch October 22, 2026 00:18
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.

1 participant