Skip to content

fix: implement variable shadowing in if/else blocks#246

Merged
cs01 merged 1 commit intomainfrom
fix/more-test-coverage
Mar 11, 2026
Merged

fix: implement variable shadowing in if/else blocks#246
cs01 merged 1 commit intomainfrom
fix/more-test-coverage

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 11, 2026

Summary

  • let x = 2 inside an if block no longer overwrites an outer let x = 1 — the outer variable is correctly restored after the block exits
  • Adds pushScope/popScope calls around if/else block generation in control-flow.ts
  • Symbol table saves and restores variable metadata (alloca, type, kind) when a name is redefined in a scope
  • Uses primitive arrays (strings, numbers) for saved state to avoid native compiler issues with object-in-array patterns

Test plan

  • New test fixture control-flow/variable-shadowing.ts — tests if/else shadowing with numbers, strings, and triple nesting
  • Updated symbol table unit tests for new shadow/restore behavior
  • All 546 tests pass (JS + native compilers)
  • Self-hosting Stage 1 passes

🤖 Generated with Claude Code

@cs01 cs01 merged commit 2322887 into main Mar 11, 2026
12 checks passed
@cs01 cs01 deleted the fix/more-test-coverage branch March 11, 2026 22:10
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