Skip to content

fix(parser-native): restore trailing return in bare switch case bodies (#597)#602

Closed
cs01 wants to merge 1 commit intomainfrom
fix/597-unary-case-block
Closed

fix(parser-native): restore trailing return in bare switch case bodies (#597)#602
cs01 wants to merge 1 commit intomainfrom
fix/597-unary-case-block

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Apr 20, 2026

Summary

Fixes #597 — the regression that blocked all stdlib additions past 8 count. Unblocks #585 (net TCP module) and every future stdlib registration.

User-facing effect

  • Compiler now correctly compiles itself when it has 8+ `registerStdlib()` calls. Previously failed with a false-positive `checkMissingReturns` error on `transformExpression`.
  • stdlib module count is no longer artificially capped.

Root cause

Parser-native's switch_case iteration was silently dropping the trailing `return` statement when a bare case body had the shape `[lexical_declaration, if_no_else, return]`. Tree-sitter reports fewer `namedChildCount` siblings than expected for this specific pattern, so the loop at `transformer.ts:2297` never visits the final `return`. The case body ended up as `[var_decl, if_no_else]` — no path returns — and `checkMissingReturns` correctly flagged it.

Only `case "unary_expression":` at `transformer.ts:528` had this 3-statement bare shape in the compiler source, so it was the lone trigger. Other bare case bodies had at most 2 statements (`[var_decl, return]`) and weren't affected.

Fix (two parts)

  1. `transformStatement` handles `statement_block`: was `return null`, now calls `transformStatementBlock` to preserve the block's contents. Without this, any `{}`-wrapped case body would silently drop.
  2. `case "unary_expression":` body wrapped in `{}`: forces tree-sitter to produce a single `statement_block` child, which now traverses correctly, preserving all three inner statements.

Followup

Test plan

  • `npm run verify` — full tests + 3-stage self-host green locally (with 8+ stdlibs — the repro threshold)
  • CI green

…ock-wrap unary_expression case body — restores trailing return dropped by bare-case iteration (#597)
@cs01 cs01 closed this Apr 21, 2026
@cs01 cs01 deleted the fix/597-unary-case-block branch April 21, 2026 04:15
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.

regression: checkMissingReturns false-positives on transformExpression when chad-native.ts has 8+ registerStdlib calls (introduced in #583)

1 participant