On this page

0013. Reject local redeclaration and shadowing

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

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.