ponyc icon indicating copy to clipboard operation
ponyc copied to clipboard

Handle Bool with exhaustive match

Open SeanTAllen opened this issue 11 months ago • 1 comments

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.

SeanTAllen avatar Dec 17 '24 19:12 SeanTAllen

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.

SeanTAllen avatar Jan 20 '25 19:01 SeanTAllen