haxe
haxe copied to clipboard
Exhaustiveness checks thrown off by enum abstract with only null value
Weird edge case incoming:
import haxe.ds.Option;
class Test {
static function main() {
switch Some(Working) {
case Some(Working | Somehow): // fine
case None:
}
switch Some(Broken) {
case Some(Broken): // [ERROR] Unmatched patterns: Some(_)
case None:
}
}
}
enum abstract Working(Null<Int>) {
var Working = null;
var Somehow = 123;
}
enum abstract Broken(Null<Int>) {
var Broken = null;
}
DECISION TREE BEGIN
7 var `<8552> = haxe.ds.Option.Some(cast null)
6 switch (`<8552>)
case Some(unguarded):
3 var `v<8553> = `<8552>[0]
2 if (`v<8553> == null)
1 else
0 <fail>
case None(unguarded):
4 default
0 <fail>
DECISION TREE END
Since we don't let the match compiler check exhaustiveness immediately, this has to be fixed in the texpr converter. We don't want to generate the if at all here because this would break apart if the switch appeared in a value-place.
I feel like I fixed this before for some empty enum case or something, will have to dig that up.