If references or (re)assignments are invalid, the compiler should throw a static semantic error.
Errors should be thrown in the following situations:
referencing an undeclared variable
referencing a variable before it is declared (temporal dead zone)
declaring the same variable twice
reassigning a fixed variable
These are semantic errors, as they are not enforceable via syntax/parsing.
Undeclared Variable Reference
If a variable is referenced but has not been declared, a ReferenceError will be thrown.
let x = y; \ ReferenceError (y is not declared)
Temporal Dead Zone
Similarly, if a variable is referenced lexically before it is declared (above, in source order), a ReferenceError will be thrown. The zone between where a variable is referenced and where it is declared below is called the “temporal dead zone”.
let x = y; \ ReferenceError (y is used before it is declared)
"
a temporal dead zone!
"
let y = 2;
Duplicate Declaration
If a variable is declared more than once, an AssignmentError will be thrown.
let x = 2;
let x = 4; \ AssignmentError (duplicate variable declaration)
Fixed Variable Reassignment
If a variable is not declared with unfixed, it is a fixed variable. If a fixed variable is reassigned, an AssignmentError will be thrown.
let x = 2;
x = 4; \ AssignmentError (reassignment of a fixed variable)
Aside: Reassigning Unfixed Variables
Variables declared with unfixed may be reassigned.
If references or (re)assignments are invalid, the compiler should throw a static semantic error.
Errors should be thrown in the following situations:
These are semantic errors, as they are not enforceable via syntax/parsing.
Undeclared Variable Reference
If a variable is referenced but has not been declared, a ReferenceError will be thrown.
Temporal Dead Zone
Similarly, if a variable is referenced lexically before it is declared (above, in source order), a ReferenceError will be thrown. The zone between where a variable is referenced and where it is declared below is called the “temporal dead zone”.
Duplicate Declaration
If a variable is declared more than once, an AssignmentError will be thrown.
Fixed Variable Reassignment
If a variable is not declared with
unfixed
, it is a fixed variable. If a fixed variable is reassigned, an AssignmentError will be thrown.Aside: Reassigning Unfixed Variables
Variables declared with
unfixed
may be reassigned.