Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exhaustiveness checks thrown off by enum abstract with only null value #11521

Open
back2dos opened this issue Jan 30, 2024 · 1 comment
Open

Comments

@back2dos
Copy link
Member

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;
}
@Simn Simn self-assigned this Jan 30, 2024
@Simn
Copy link
Member

Simn commented Jan 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants