Skip to content

🐛 Fix false 'not declared' error when destructuring reassigned variables#120

Merged
timfennis merged 2 commits intomasterfrom
bugfix/unpack-mismatched-tuple-arity
Mar 21, 2026
Merged

🐛 Fix false 'not declared' error when destructuring reassigned variables#120
timfennis merged 2 commits intomasterfrom
bugfix/unpack-mismatched-tuple-arity

Conversation

@timfennis
Copy link
Owner

Summary

  • When a variable was declared as () and later reassigned to a tuple (e.g. let pos = (); pos = (1, 2);), destructuring it with let a, b = pos; would produce a false "Identifier a has not previously been declared" error
  • Root cause: the analyser inferred the type from the initial declaration (Tuple([])), and zip with an empty iterator silently produced zero bindings for the lvalues
  • Fix: when a Tuple's arity doesn't match the number of lvalues in the destructuring, fall back to Any for each element instead of silently skipping them

Test plan

  • Added regression test bug0015_unpack_mismatched_tuple_arity.ndc
  • Verified test fails without the fix
  • All 268 tests pass

🤖 Generated with Claude Code

timfennis and others added 2 commits March 21, 2026 22:42
When a variable was declared as `()` and later reassigned to a tuple
(e.g. `let pos = (); pos = (1, 2);`), destructuring it with
`let a, b = pos;` would silently fail to declare `a` and `b` because
the analyser saw an empty tuple and `zip` produced zero iterations.

Now falls back to `Any` when a Tuple's arity doesn't match the number
of lvalues, allowing the destructuring to proceed to runtime.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timfennis timfennis enabled auto-merge (squash) March 21, 2026 21:44
@timfennis timfennis merged commit 4cdadc7 into master Mar 21, 2026
1 check passed
@timfennis timfennis deleted the bugfix/unpack-mismatched-tuple-arity branch March 21, 2026 21:45
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