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

    TPZ5721: Loop break values do not agree

    A loop expression has break values whose types cannot join to one result type.

    Diagnostic and cause

    Link

    Loop break values do not agree

    Family
    topaz
    Phase
    check
    Code
    TPZ5721

    Cause and conditions

    When a value-producing loop has no contextual result type, incompatible break-value types are rejected with TPZ5721. The int and string break values in this program are assignable in neither direction.

    Response

    Make the breaks produce compatible values. The repaired program returns int from both branches.

    Source evidence

    Compiler phase: check.

    Compiler explanation: A loop expression has break values whose types cannot join to one result type.

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

    • break values targeting this loop disagree — earlier break is ⟨value⟩, this is ⟨value⟩ (all break values must have the same type) Source

    When a value-producing loop has no contextual result type, incompatible break-value types are rejected with TPZ5721. The int and string break values in this program are assignable in neither direction.

    Rulediagnostics.tpz5721.p5.rule

    Inferred loop break types must be compatible

    When a value-producing loop has no contextual result type, incompatible break-value types are rejected with TPZ5721. The int and string break values in this program are assignable in neither direction.

    Source evidence

    Response

    Link

    Make the breaks produce compatible values. The repaired program returns int from both branches.

    Reproduction and verification

    Link

    Rejected program

    Link
    example.tpzRejected programOpen in Playground
    1. let flag: bool = true
    2. let result = loop {
    3. if (flag) { break 1 } else { break "text" }
    4. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5721 diagnostic-tpz5721 at example.tpz:3:32

    This condition applies to a value loop with no expected result type and concrete incompatible break types. The checker compares assignability in both directions; the example does not impose a type-spelling equality rule on other loop contexts.

    Source evidence

    Repaired program

    Link
    example.tpzRepaired program
    1. let flag: bool = true
    2. let result = loop {
    3. if (flag) { break 1 } else { break 2 }
    4. }
    Expected outputexit 0
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    This condition applies to a value loop with no expected result type and concrete incompatible break types. The checker compares assignability in both directions; the example does not impose a type-spelling equality rule on other loop contexts.

    Source evidence

    Menu

    Download