Diagnostic and cause
Uninitialized binding read
- Семейство
- topaz
- Этап
- run
- Код
TPZ5002
Причина и условия
Module-level let bindings become ready after their initializers complete, and function bindings become ready at their declaration position. A direct initializer read of the same or a later runtime binding is rejected with TPZ3018 during resolution in entry and imported files alike. The direct check follows an if or while condition, a match scrutinee, a for iterator, and the first comprehension source. It does not enter function, lambda, branch, arm, or loop bodies. Short-circuit right operands and optional-call arguments are delayed as well. A delayed reference reads the binding when execution reaches it. Reading before initialization faults with TPZ5002; reading after initialization returns the current value. Merely storing a closure does not evaluate its body.
Связанное правило · Initialization through branches, calls, and closures →Действия
Compiler phase: runtime.
Message templates are Pending.
A reference in a branch, call, or closure body reads a module binding when execution reaches it. Reading the binding before its initializer completes faults with TPZ5002. Reading it after initialization returns the current value.
A read or write reaches an uninitialized binding
- Семейство
- topaz
- Этап
- run
- Код
TPZ5002- Режим языка
- 6.0
- Продукт
- Не выпущен
Причина и условия
A block function becomes available to ordinary reads at its declaration statement. Starting at the entry to the declaring block, plain nested blocks and a concurrent timeout expression keep the surrounding evaluation path. Function and lambda bodies, defer bodies, conditional evaluation, concurrent arms, and the timeout else body delay a read. The scrutinee keeps its enclosing evaluation path. Entering a pattern adds a conditional boundary, and a case guard or arm runs after its pattern succeeds. Static types, pattern position, and literal values do not change the boundary. The checker still checks names and types in expressions that execution skips. An immediate read before the declaration produces TPZ3018 at the reference. Reading or writing the selected binding before initialization during execution faults with TPZ5002 at the access. A constant alias can call the function before its declaration and retain it after leaving the block. In that call the function’s unshadowed self-reference names the called value. Ordinary reads of the binding still depend on whether its declaration ran.
In Topaz 6.0, entry and imported modules use the same initialization order. The right-hand side of let, if let, and while let, the match scrutinee, the for iterable, and the first comprehension source inherit the enclosing evaluation path. Entering any pattern delays its expressions, including range endpoints. In a comprehension, later sources, filters, and the result expression are delayed too. A pattern installs its bindings after the whole pattern succeeds. An immediate read of an uninitialized module binding produces resolve TPZ3018. A delayed read faults with TPZ5002 if execution reaches it before initialization.
Readiness is judged at the cell of the selected target when an access first reaches it. A module let, let mut, destructuring, or function binding is initialized by its own statement. On the immediate module path, reading or writing a binding that is not initialized yet is rejected during resolution with TPZ3018, and replacing an imported binding is rejected with TPZ3015. Function and lambda bodies delay their accesses. A delayed access that reaches the cell before initialization faults with TPZ5002 at the access.
Write permission belongs to the declaration. After resolution succeeds, a name, field, or index assignment, or a mutator call such as xs., whose root is immutable is rejected during checking with TPZ5003. Declaration order and whether the write can run do not matter. A simple name assignment evaluates its right operand before it checks the target cell. A field assignment headed by a name evaluates the right operand before it reads the root. An index assignment and a compound assignment read the receiver or target before the right operand.
Действия
Response
Declare the binding before the code that reads it runs, or move the read into code that runs after the initializer completes.
Reproduction and verification
An executed branch faults before a later binding initializes
let chosen: int = if (true) { after } else { 0 }let after: int = 7
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Этап отклонения run. Ненулевой код завершения.
bindings-runtime-uninitialized-read at
example.tpz:1:31