Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Diagnostics

    TPZ5612: Empty comprehension needs a type

    An empty comprehension cannot infer its element, key, or value type.

    Diagnostic and cause

    Link

    Empty comprehension needs a type

    Family
    topaz
    Phase
    check
    Code
    TPZ5612

    Cause and conditions

    An unannotated comprehension binding whose body type remains unresolved is rejected with TPZ5612. Giving its input array an element type makes the result inferable.

    Response

    Give the input collection a concrete element type. The repaired program annotates an empty input as Array<int> before using its elements in the comprehension.

    Source evidence

    Compiler phase: check.

    Compiler explanation: An empty comprehension cannot infer its element, key, or value type.

    Message templates. The marker ⟨value⟩ stands for text computed for the reported program.

    • this comprehension's element type cannot be inferred (§6.4): annotate the binding with its collection type Source

    An unannotated comprehension binding whose body type remains unresolved is rejected with TPZ5612. Giving its input array an element type makes the result inferable.

    Rulediagnostics.tpz5612.p5.rule

    Comprehension element type needs input context

    An unannotated comprehension binding whose body type remains unresolved is rejected with TPZ5612. Giving its input array an element type makes the result inferable.

    Source evidence

    Response

    Link

    Give the input collection a concrete element type. The repaired program annotates an empty input as Array<int> before using its elements in the comprehension.

    Reproduction and verification

    Link

    Rejected program

    Link
    example.tpzRejected programOpen in Playground
    1. let values = [for value in ([]) => value]
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5612 diagnostic-tpz5612 at example.tpz:1:14

    The empty input can also trigger TPZ5020. The required TPZ5612 refers to the complete comprehension. Supplying a typed input establishes the repair independently of result-context propagation.

    Source evidence

    Repaired program

    Link
    example.tpzRepaired program
    1. let input: Array<int> = []
    2. let values = [for value in (input) => value]
    Expected outputexit 0
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    The empty input can also trigger TPZ5020. The required TPZ5612 refers to the complete comprehension. Supplying a typed input establishes the repair independently of result-context propagation.

    Source evidence

    Menu

    Download