haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Exhaustiveness checks thrown off by enum abstract with only null value

Open back2dos opened this issue 1 year ago • 1 comments

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;
}

back2dos avatar Jan 30 '24 12:01 back2dos

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.

Simn avatar Jan 30 '24 15:01 Simn