본문으로 건너뛰기
토파즈문서
6.05.21

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    다운로드 →

    진단 TPZ5002

    A delayed read reaches a binding before its initializer completes and produces TPZ5002 at run time.

    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.

    대응

    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.push(8), 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

    example.tpzAn executed branch faults before a later binding initializes플레이그라운드 열기 →
    1. let chosen: int = if (true) { after } else { 0 }
    2. let after: int = 7
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz run example.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 run. 종료 코드가 0이 아닙니다.

    • TPZ5002 →

      bindings-runtime-uninitialized-read at example.tpz:1:31