Pattern match cases that follow wildcard patterns aren't always marked as unreachable
yorickpeterse opened this issue · comments
Please describe the bug
When one or more pattern match cases follow a case that uses a wildcard pattern, these patterns aren't always correctly marked as unreachable.
This issue also affects Gleam (gleam-lang/gleam#2651), suggesting it's a problem with the underlying algorithm from https://github.com/yorickpeterse/pattern-matching-in-rust.
The issue seems to be specific to literals, i.e. patterns that are treated as having an infinite range. The following works as expected:
class enum Letter {
case A
case B
case C
case D
}
class async Main {
fn async main {
match Letter.A {
case A -> 'one'
case B -> 'two'
case _ -> 'else'
case C -> 'three'
}
}
}
Please list the exact steps necessary to reproduce the bug
Save the following as test.inko
:
class async Main {
fn async main {
match 42 {
case 1 -> 'one'
case 2 -> 'two'
case _ -> 'else'
case 3 -> 'three'
}
}
}
Now run inko check test.inko
. This should produce a warning that the case 3 -> 'three'
line is unreachable, but instead no warnings are produced.
Operating system
Fedora 39
Inko version
main
Rust version
1.77.1