0013. Reject local redeclaration and shadowing
- Status: Accepted; revisit after T0 (M2.6)
- Date: 2026-10-29
- Plan: M2.1, M2.6
- Review: The biggest risk: models have never seen Tenon
Context
Models need one predictable rule for local names (ADR-0009). M1's resolver already has lexical scopes but permits names to hide earlier declarations.
Decision
Reject redeclaring a local in the same block with E0208. Reject
shadowing any outer local, including a parameter, with E0209, for
both let and var. Parameters occupy the
scope enclosing the function body. Sibling blocks may reuse a name
after its scope ends. Initializers resolve before binding.
Locals and functions are separate namespaces until first-class functions exist; a local may share a function or builtin name without hiding calls.
Alternatives considered
- Rust-style rebinding
(
let x = x + 1) — convenient but silently changes which declaration a name means. If T0 shows models rely on it frequently, revisit after M2.6 with a superseding ADR. - Allow only nested-block shadowing — makes the rule depend on placement and still hides outer values; one rule without exceptions is easier to teach.
Consequences
Accidental hiding becomes a diagnostic with a repair.
Transformations need distinct names or assignment to a
var. Cgen retains unique local renaming; the M1
nested-scopes golden uses distinct names with unchanged
output.