Diagnostic and cause
LinkLoop 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/crates/topaz_diag/src/explain.rs at
151141d7bb44· 971-980 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 473-473 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 425-480
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.
breakvalues targeting this loop disagree — earlierbreakis⟨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.
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
- compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 425-480
Response
LinkMake the breaks produce compatible values. The repaired program returns int from both branches.
Reproduction and verification
LinkRejected program
Linklet flag: bool = truelet result = loop {if (flag) { break 1 } else { break "text" }}
No stdout.
Expected result
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
- compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 425-480
Repaired program
Linklet flag: bool = truelet result = loop {if (flag) { break 1 } else { break 2 }}
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
- compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 425-480