Skip to content

Variable Declarations and Assignment

Overview

Local variables are declared with let and initialized with an expression. Assignment updates the value of an existing variable.

Syntax

let x = 123;

x = 456;

Rules

Mandatory Initialization

Variable declarations MUST include an initializer.

Type Inference

The type MUST be inferred from the initializer expression. Explicit type annotations on local variable declarations MUST NOT be supported. Function parameters and return types are the only declarations that MUST be explicitly typed.

Assignment

Assignment updates the value of a variable. The type of the assigned expression MUST be implicitly convertible to the variable's type. All primitive types MUST be implicitly convertible to all other primitive types during assignment. Handles MUST NOT be implicitly converted. Function pointers MUST NOT be converted.

Shadowing Prohibition

Redeclaring a variable MUST produce a compile error. Shadowing is STRICTLY PROHIBITED.

Variable Scope

Variables declared with let MUST be block-scoped. A variable MUST only be accessible within the braced block in which it is declared. A variable MUST NOT be accessible outside its declaring block.

Primitive Conversion Semantics

When a primitive value is implicitly converted to a narrower type, the value MUST be truncated. When a signed integer is converted to an unsigned integer of the same width, the bit pattern MUST be preserved (two's complement reinterpretation). When an unsigned integer is converted to a signed integer of the same width, the bit pattern MUST be preserved. When a floating-point value is converted to an integer, the fractional part MUST be discarded (truncation toward zero). When an integer is converted to a floating-point type, the value MUST be rounded to the nearest representable value. Runtime integer overflow during conversion MUST wrap according to two's complement arithmetic.