You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following function has an exhaustive pattern match which is correctly identified as such:
f : [A, B], U8 -> Boolf = \x, y ->
when x isA -> Bool.trueB -> Bool.false_if y >1 -> Bool.false
Note that the wildcard does not make this pattern exhaustive. This is already covered by the cases A and B.
When the wildcard pattern is moved in between the A and B patterns, the following code is still fine:
f : [A, B], U8 -> Boolf = \x, y ->
when x isA -> Bool.true_if y >1 -> Bool.falseB -> Bool.false
However, when making the the wildcard pattern the first pattern of the match roc check incorrectly reports this as an error:
── UNSAFE PATTERN in src/Test.roc ──────────────────────────────────────────────
This when does not cover all the possibilities:
5│> when x is
6│> _ if y > 1 -> Bool.false
7│> A -> Bool.true
8│> B -> Bool.false
Other possibilities include:
_ (note the lack of an if clause)
I would have to crash if I saw one of those! Add branches for them!
────────────────────────────────────────────────────────────────────────────────
1 error and 0 warnings found in 42 ms
The text was updated successfully, but these errors were encountered:
phagenlocher
changed the title
Wildcard with if in first position breaks exhaustiveness of pattern match
Wildcard pattern with guard in first position breaks exhaustiveness of pattern match
Nov 30, 2024
The following function has an exhaustive pattern match which is correctly identified as such:
Note that the wildcard does not make this pattern exhaustive. This is already covered by the cases
A
andB
.When the wildcard pattern is moved in between the
A
andB
patterns, the following code is still fine:However, when making the the wildcard pattern the first pattern of the match
roc check
incorrectly reports this as an error:The text was updated successfully, but these errors were encountered: