Skip to content

Fix variable redeclaration in flattened SEQ scopes#101

Merged
associate-1 merged 1 commit intomainfrom
fix/var-redecl-scoping
Mar 4, 2026
Merged

Fix variable redeclaration in flattened SEQ scopes#101
associate-1 merged 1 commit intomainfrom
fix/var-redecl-scoping

Conversation

@associate-1
Copy link
Member

Summary

  • When occam code declares the same variable name in separate sequential regions (sibling SEQ blocks or repeated declarations within a proc/func body), the generated Go code emitted multiple var x type at the same scope level, causing redeclared in this block errors
  • Add generateStatementsWithScoping() that tracks declared names and opens new Go { } scope blocks on redeclaration, plus declaredNames() which recursively collects names from transparent (non-replicated) SEQ blocks
  • Fixes test_bell.occ (again declared twice) and test_utils.occ (ch declared three times)

Test plan

  • All existing tests pass (go test ./...)
  • New e2e test TestE2E_VarRedeclInSiblingSeqs — variable declared in three sibling SEQ blocks transpiles, compiles, and runs correctly
  • test_bell.occ transpiles and passes go vet
  • test_utils.occ transpiles and passes go vet
  • Course module still transpiles and passes go vet

🤖 Generated with Claude Code

When occam code declares the same variable name in separate sequential
regions (e.g. sibling SEQ blocks or repeated declarations within a proc
body), the generated Go code emitted multiple `var x type` declarations
at the same scope level, causing "redeclared in this block" errors.

Add generateStatementsWithScoping() that tracks declared names and opens
new Go { } scope blocks when a redeclaration is detected. The companion
declaredNames() helper recursively collects names from non-replicated
SEQ blocks since those are transparent in Go (no braces).

Fixes test_bell.occ and test_utils.occ transpilation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@associate-1 associate-1 merged commit 875624e into main Mar 4, 2026
1 check passed
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.

2 participants