Skip to content

fix: scope Strong switch arms independently - #1040

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/fix-strong-switch-scope-1037
Sep 10, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/fix-strong-switch-scope-1037

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Analyze each @switch arm in its own function scope, with the case tests in their enclosing scope. This fixes false module/ref diagnostics and missed ref, state getter, setter, and snapshot diagnostics.
  • Keep var reassignment proofs separate across sibling arms, and classify non-static class field initializers as deferred while preserving checks on static fields and computed keys.

Why

Addresses the checked Strong mode work in point 2 of #1037. The phase analyzer previously descended into switch arms without creating their scopes, even though the locality walker and emitted arm callbacks already gave each arm its own lifetime.

Changes

  • Add a dedicated JSXSwitchExpression visitor and arm-local hoisted-variable scopes.
  • Match those scopes in the reassignment pass used by Strong diagnostics.
  • Add regressions for arm shadowing, sibling isolation, arm-local functions, class field timing, and unchanged client/server output.
  • Add an octane patch changeset.

Validation

  • pnpm format:check (scoped check below passed)
  • pnpm typecheck (scoped check below passed)
  • pnpm test (attempted; unrelated local browser projects failed, so the run was stopped)
  • targeted tests: pnpm exec vitest run --project octane --project octane-prod (991 files, 17,787 passed, 14 expected failures on the rebased head)
  • pnpm typecheck:files packages/octane/src/compiler/strong-mode.js packages/octane/src/compiler/hook-deps.js packages/octane/tests/compiler/strong-mode.test.ts
  • pnpm format:files:check packages/octane/src/compiler/strong-mode.js packages/octane/src/compiler/hook-deps.js packages/octane/tests/compiler/strong-mode.test.ts .changeset/strong-switch-arm-scopes.md
  • pnpm sync (clean)

Risk / follow-ups

Provenance

  • An agent produced this diff (agent-authored)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Changes opt-in Strong-mode static analysis and hook binding walks only; emitted code is unchanged in tests, but new per-arm scopes could surface or clear diagnostics in edge cases around template switches and in-render classes.

Overview
Strong mode now analyzes each @switch arm in its own lexical scope, matching how the compiler already emits separate arm callbacks. Case discriminants and tests stay in the parent scope; arm bodies get per-arm function scopes in both the render-phase analyzer (strong-mode.js) and the reassignment/binding walk used for diagnostics (hook-deps.js).

That fixes false positives (e.g. arm-local const shadowing module revision) and false negatives (refs, state getters/setters, and snapshot mutations declared in one arm no longer leak to siblings). Case labels are checked before entering the arm scope so reads like @case revision still flag module-state use during render.

Instance (non-static) class field initializers are visited in the deferred execution phase when a class is defined during render, so initializer reads are not treated as synchronous render work; static fields and methods keep the prior timing (static initializers still run at class definition time).

Regression tests cover arm shadowing, sibling isolation, arm-local functions, unchanged client/server codegen under Strong vs ordinary compile, and class field timing. Includes an octane patch changeset.

Reviewed by Cursor Bugbot for commit d797447. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 10, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 10, 2026 18:56
@domgan-oai
domgan-oai merged commit c3b0bea into octanejs:main Sep 10, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant