1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-11 02:02:58 +00:00

Analyzer: E0502 on assignment to undefined variable

Previously an assignment to an undeclared name was silently accepted
because the IR lowering would synthesize a fresh VarId for it. Now
the analyzer emits E0502 with the same "did you mean" suggestion
path as read-side undefined variable errors.

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
Claude 2026-04-12 16:35:49 +00:00
parent 1778ae0ec8
commit 59970a4a45
No known key found for this signature in database
2 changed files with 24 additions and 0 deletions

View file

@ -797,6 +797,11 @@ impl Analyzer {
*span,
));
}
} else {
// Assigning to an undeclared name is an
// error — the lowering would otherwise
// silently synthesize a VarId for it.
self.emit_undefined_var(name, *span);
}
}
LValue::ArrayIndex(name, idx) => {
@ -808,6 +813,8 @@ impl Analyzer {
*span,
));
}
} else {
self.emit_undefined_var(name, *span);
}
// Indexing an array counts as a read of the array,
// and the index expression itself may contain reads.