Diagnostic and cause
LinkOr-pattern binding types disagree
- Family
- topaz
- Phase
- check
- Code
TPZ5711
Cause and conditions
Binding the same name to disjoint payload types across or-pattern alternatives is rejected with TPZ5711. In this program, int and string cannot give value a compatible binding type.
Response
Use compatible payload types for a shared binding, or split the alternatives into separate arms. The repaired enum supplies int from both alternatives.
Source evidence
- compiler/crates/topaz_diag/src/explain.rs at
151141d7bb44· 951-960 - compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
151141d7bb44· 1552-1552 - compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1507-1562 - compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1381-1421 - compiler/crates/topaz_self_frontend/topaz/checker/type_algebra.tpz at
17711dcdbc9b· 45-60
Compiler phase: check.
Compiler explanation: A name bound by multiple alternatives of an or-pattern has inconsistent types.
Message templates. The marker ⟨value⟩ stands for text computed for the reported program.
- binding
⟨value⟩has type⟨value⟩in one or-pattern alternative and⟨value⟩in another Source
Binding the same name to disjoint payload types across or-pattern alternatives is rejected with TPZ5711. In this program, int and string cannot give value a compatible binding type.
Or-pattern binding types must be compatible
Binding the same name to disjoint payload types across or-pattern alternatives is rejected with TPZ5711. In this program, int and string cannot give value a compatible binding type.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1507-1562 - compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1381-1421 - compiler/crates/topaz_self_frontend/topaz/checker/type_algebra.tpz at
17711dcdbc9b· 45-60
Response
LinkUse compatible payload types for a shared binding, or split the alternatives into separate arms. The repaired enum supplies int from both alternatives.
Reproduction and verification
LinkRejected program
Linkenum Item { Count(int), Text(string) }function read(item: Item) -> int {match (item) {case Count(value) | Text(value) => 0}}
No stdout.
Expected result
The checker tests whether the collected types are disconnected under type overlap. This example establishes the disjoint int/string case; it does not require all alternative type spellings to be identical.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1507-1562 - compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1381-1421 - compiler/crates/topaz_self_frontend/topaz/checker/type_algebra.tpz at
17711dcdbc9b· 45-60
Repaired program
Linkenum Item { Count(int), Text(int) }function read(item: Item) -> int {match (item) {case Count(value) | Text(value) => 0}}
Expected result
Expected result
Checking accepts the program. Exit code 0.
The checker tests whether the collected types are disconnected under type overlap. This example establishes the disjoint int/string case; it does not require all alternative type spellings to be identical.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1507-1562 - compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1381-1421 - compiler/crates/topaz_self_frontend/topaz/checker/type_algebra.tpz at
17711dcdbc9b· 45-60