Diagnostic and cause
Range pattern matches no value
- Family
- topaz
- Phase
- check
- Code
TPZ5714
Cause and conditions
An integer range pattern compares an int scrutinee with int endpoints. The value must be greater than or equal to the lower endpoint and satisfy the upper comparison. Both comparisons must succeed. The pattern introduces no bindings.
| Pattern operator | Upper comparison |
|---|---|
. | Less than or equal to the upper endpoint |
. | Less than the upper endpoint |
Response
Choose endpoints and an operator that describe a nonempty interval, or remove the empty pattern. Use (0 . when the single value 0 is intended. An exclusive upper endpoint equal to the lower endpoint matches nothing.
Topaz 6.0 reports TPZ5714 during checking. Its primary location is the empty range pattern. The diagnostic retains both written endpoints and the operator. Endpoint type checking and TPZ5001 literal-range checking run first. No product execution is recorded for these examples.
A literal exclusive range (a . is empty when a is greater than or equal to b. A literal inclusive range (a . is empty when a is greater than b. Negative literals and endpoints in simple grouping parentheses follow the same rule. Every pattern position is covered, including alternatives, nested patterns, for patterns, and destructuring.
The integer range rule defines this rejection under empty-range-patterns.1. Computed endpoints are not checked for static emptiness. Their evaluation follows range-endpoint-evaluation.1, and an empty computed interval simply does not match. TPZ5713 continues to diagnose complete coverage by earlier unguarded match cases. It does not replace TPZ5714 for an empty subpattern.
Response
Choose endpoints and an operator that describe a nonempty interval, or remove the empty pattern. Use (0 . when the single value 0 is intended. An exclusive upper endpoint equal to the lower endpoint matches nothing.
Reproduction and verification
Rejected empty range
function classify(value: int) -> int {match (value) {case (0 ..< 0) => 1case _ => 0}}
No stdout.Expected result
Expected result
Rejection during check. Nonzero exit.
range-pattern-empty at
example.tpz:3:10
The exclusive range (0 . contains no int. Its two literal endpoints and operator identify the invalid pattern.
Repaired nonempty range
function classify(value: int) -> int {match (value) {case (0 .. 0) => 1case _ => 0}}
Expected result
Expected result
Checking accepts the program. Exit code 0.
The inclusive range (0 . contains one int. The fallback handles every other input.