ReviewOS

zig-utils/zig-js

Parser: allow using declarations directly in switch CaseBlocks

#835
Closed chris opened this 9 days ago ·
9 days ago

Problem

The parser rejects an explicit resource-management declaration used directly as a SwitchClause StatementListItem:

switch (0) {
  case 0:
    using value = { [Symbol.dispose]() {} };
    break;
}

The failure is ParseError.UnexpectedToken from parseStatementInner because parseSwitch does not establish the same using_allowed statement-list context as program/function/block parsing. The VM and tree-walker already implement CaseBlock lexical environments and disposal machinery; rejecting the syntax masks that runtime path.

Discovered while adding the forced-moving switch-environment witness for #834. The #834 test uses a lexical let to keep GC scope separate; this parser issue must not be worked around by rewriting source or broadening exclusions.

Acceptance

  • Parse using declarations as direct StatementListItems in switch cases where the Explicit Resource Management grammar permits them.
  • Preserve early errors, TDZ/duplicate-binding checks across the whole CaseBlock, fall-through ordering, break/return/throw completion threading, and reverse-order disposal.
  • Cover normal and abrupt completion in tree-walker and required-bytecode modes, including a disposal error and a moving-GC callback.
  • Add the relevant nonzero test262 Explicit Resource Management / switch census and run focused OOM, TSan, and full unit gates.

Related: #834, #465.

9 days ago

Closing after checking the pinned test262 corpus and the Explicit Resource Management early-error rule. Direct declarations in either clause StatementList are required to be rejected:

  • test/language/statements/using/syntax/with-initializer-case-expression-statement-list.js
  • test/language/statements/using/syntax/with-initializer-default-statement-list.js
  • test/language/statements/await-using/syntax/with-initializer-case-expression-statement-list.js
  • test/language/statements/await-using/syntax/with-initializer-default-statement-list.js

The existing parser behavior is standards-conformant. The valid spelling is a nested block, for example case 0: { using value = resource; break; }. No engine change is appropriate; the issue was based on a mistaken grammar reading discovered during #834 and is withdrawn to avoid a conformance regression.

Sign in to comment on this issue.