Skip to content

fix: preserve switch boundaries before lambda results - #39

Merged
exKAZUu merged 1 commit into
mainfrom
fix/switch-lambda-results
Oct 22, 2026
Merged

exKAZUu merged 1 commit into
mainfrom
fix/switch-lambda-results

Conversation

@exKAZUu

@exKAZUu exKAZUu commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Why

A switch result lambda can absorb the preceding rule arrow into the case label or guard. For example, case A + B -> value -> value + 2 produces a lambda inside the label without a syntax error. Twelve compiler-valid forms in the regression fixture have this incorrect boundary.

Requirements

  • required: Improve the forked grammar repositories, excluding CSS and Markdown, ignoring backward compatibility; review fork issues and major upstream issues, PRs and recent commits, and resolve eligible items.
  • required: Prevent duplicate PRs, and create a dedicated PR from the latest main for each identified issue or upstream item that warrants resolution.
  • required: Run review-booster and complete-pr concurrently, then release the changes; continue until all eligible upstream items are processed.
  • required: Valid Java switch labels, guards and result lambdas must retain their syntactic boundaries, with queryable parameters, bodies and source ranges.
  • chosen: Address the upstream switch/lambda boundary origin separately by lowering lambda precedence; restricting only root label and guard alternatives leaves compiler-valid nested operands broken.
  • chosen: Keep the existing label and guard expression alternatives, public node schema and lambda fields; this smaller change preserves legitimate nested guard lambdas and independent cast, curried, conditional and argument lambdas in the measured controls.
  • chosen: Use compiler-validated regression fixtures plus focused parser, query and incremental-edit checks to verify the observable boundary behavior.

Customer Summary

Switch rules returning lambdas now keep their constant expressions and guards separate from the result lambda, including arithmetic, unary, conditional and cast expressions.

Technical Summary

grammar.js gives lambda_expression the lowest named precedence and removes its obsolete conflict with primary expressions. The generated parser retains the public node schema. Two corpus cases cover switch results and independent lambda contexts, including legitimate lambdas nested inside guards.

Testing

  • Official JDK 27 compiled the 19-method switch fixture and eight-method/one-field lambda control fixture without diagnostics.
  • Canonical generation and all 165 native/Wasm corpus cases passed; 69 focused tests across 13 files passed.
  • Manual public API checks verified 34 switch rules, lambda parameter/body fields, shipped tags, and eight incremental edit/undo states. Exactly twelve method trees change; seven other methods, all token metadata and all shipped tags match published 9.0.0.
  • Full tree metadata and shipped queries match published 9.0.0 for 33 control programs and the independent lambda fixture; 240 whitespace trees and six CST/query/edit controls also match. The public schema is unchanged.
  • bun run verify passed with zero code-gauge violations. Rust unit and documentation tests passed. Incremental fuzzing passed all 165 cases with 100 iterations and ten edits, explicitly using seed 1.
  • All PR CI checks passed, including the full suite, native platform jobs, Rust and fuzzing.

Notes

The upstream root-expression exclusions alone miss nested arithmetic operands, so this change uses precedence instead. Compiler-rejected assignment guards and an unparenthesized expression-bodied cast-lambda guard are excluded from the positive fixtures. The measured controls establish scoped parity rather than universal grammar equivalence.

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@exKAZUu exKAZUu self-assigned this Oct 22, 2026
@exKAZUu
exKAZUu merged commit 5222c8c into main Oct 22, 2026
10 checks passed
@exKAZUu
exKAZUu deleted the fix/switch-lambda-results branch October 22, 2026 00:58
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