ponyc
ponyc copied to clipboard
Handle Bool with exhaustive match
Currently, the following code isn't seen as an exhaustive match:
actor Main
new create(env: Env) =>
env.out.print("Hello World")
fun box fourty_two(err: Bool = false): USize ? =>
match err
| true =>
return 50
| false =>
return 42
end
This is surprising to folks and we believe that exhaustiveness checking should be enhanced to handle this for booleans.
This bit in match.c would need to change for this to work.
// Only cases that match on type alone can count toward exhaustive match,
// because matches on structural equality can't be statically evaluated.
// So, for the purposes of exhaustive match, we ignore those cases.
if(!case_expr_matches_type_alone(opt, case_expr))
continue;
in the case of a boolean, we can do the match.