Diagnostic and cause
LinkUnreachable match case
- Family
- topaz
- Phase
- check
- Code
TPZ5713
Cause and conditions
Cases are tried in source order. A case may overlap an earlier case if it can match an input that reaches it. A specific case can therefore precede a general case. An unguarded wildcard or total binding is an ordinary case and acts as a fallback at its written position. There is no separate residual fallback selection.
A later case is unreachable when the union of preceding unguarded patterns covers every value its pattern could match. This includes a case shadowed by a single catch-all or by several earlier cases. Pattern typing runs before this comparison. A guard cannot establish unconditional coverage because it may fail. Overlapping cases with reachable inputs remain valid even when their intersection is unknown.
Alternatives of one or-pattern describe one case domain. Their overlap does not make a later case unreachable. Binding consistency is checked by its separate rule. All case bodies are checked even when their patterns are unreachable.
An unreachable case is rejected during checking with TPZ5713. A typed pattern incompatible with the known scrutinee type still uses TPZ5001. Match completeness follows the exhaustiveness rule.
During checking, TPZ5713 rejects a match case when the union of earlier unguarded patterns covers every value that its pattern can match. The primary location is the start of the unreachable pattern. Pattern typing runs before coverage comparison. A guard on an earlier case never establishes unconditional coverage, even when the guard is constant. A later guarded case is still unreachable when earlier unguarded patterns cover its entire pattern domain. Reachable overlap and a general case after a specific case remain valid. If coverage cannot be proved, the case remains valid under this rule. Alternatives of one or-pattern form one case domain. Their mutual overlap does not trigger this diagnostic. Every case body is type checked. Existing completeness checks remain unchanged. The pattern matching rule defines ordered selection and reachability.
Related rule: Earlier cases cover this match caseResponse
Move general unguarded cases after any specific cases they would shadow. Remove a later case if earlier unguarded patterns already cover all inputs it could match. A guard may fail and does not establish unconditional coverage.
Source evidence
- inferMatchExpression at
72a59a31125f· 216-316 - emitMatch at
72a59a31125f· 2274-2308 - planPattern at
72a59a31125f· 2055-2094 - issues/31 at
72a59a31125f
Topaz 6.0.0 specifies this diagnostic during checking.
The target message is match case is unreachable because earlier unguarded cases cover its pattern.
The pinned SELF source does not emit this diagnostic.
Earlier unguarded cases cover every input that could match this case. The checker reports TPZ5713 at the unreachable pattern. In the example, true and false together cover every bool value before the wildcard case.
Earlier cases cover this match case
During checking, TPZ5713 rejects a match case when the union of earlier unguarded patterns covers every value that its pattern can match. The primary location is the start of the unreachable pattern. Pattern typing runs before coverage comparison. A guard on an earlier case never establishes unconditional coverage, even when the guard is constant. A later guarded case is still unreachable when earlier unguarded patterns cover its entire pattern domain. Reachable overlap and a general case after a specific case remain valid. If coverage cannot be proved, the case remains valid under this rule. Alternatives of one or-pattern form one case domain. Their mutual overlap does not trigger this diagnostic. Every case body is type checked. Existing completeness checks remain unchanged. The pattern matching rule defines ordered selection and reachability.
Why
An exceptional case can intentionally precede a general case. Source order expresses that priority. Rejecting a case already covered by earlier unguarded patterns prevents that order from silently disabling a branch. A guard can fail, so it cannot establish unconditional coverage. This follows the ordered match decision.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 214-306 - issues/31 at
72a59a31125f
Response
LinkRemove the covered case, or place a specific case before a general case that should handle the remaining inputs. If an earlier case is conditional, express that condition with a guard. The corrected program keeps the true case before the wildcard.
Reproduction and verification
LinkRejected program
Linkfunction classify(value: bool) -> int {match (value) {case true => 1case false => 0case _ => 2}}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5713match-unreachable-case atexample.tpz:5:10
The message pattern is the Topaz 6.0 target message. The cited SELF source checks completeness but does not emit TPZ5713. The rejected program exercises the union of two earlier unguarded cases. The corrected program keeps a reachable general case after a specific case.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 214-306 - issues/31 at
72a59a31125f
Repaired program
Linkfunction classify(value: bool) -> int {match (value) {case true => 1case _ => 0}}
Expected result
Expected result
Checking accepts the program. Exit code 0.
The message pattern is the Topaz 6.0 target message. The cited SELF source checks completeness but does not emit TPZ5713. The rejected program exercises the union of two earlier unguarded cases. The corrected program keeps a reachable general case after a specific case.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 214-306 - issues/31 at
72a59a31125f