Skip to content

Wildcard pattern with guard in first position breaks exhaustiveness of pattern match #7278

Open
@phagenlocher

Description

@phagenlocher

The following function has an exhaustive pattern match which is correctly identified as such:

f : [A, B], U8 -> Bool
f = \x, y ->
    when x is
        A -> Bool.true
        B -> 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 -> Bool
f = \x, y ->
    when x is
        A -> Bool.true
        _ if y > 1 -> Bool.false
        B -> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions