HaxeFoundation / HaxeFoundation/haxe

Guard messes up exhaustiveness check.

Open
#6,769 4 comments 0 reactions 1 assignee Claimed by @Simn View on GitHub
bug feature-pattern-matching
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

The following [produces](https://try.haxe.org/#dfC1F) `Unmatched patterns: Success`:

```haxe
using tink.CoreApi;

class Test {
static function main() {
switch Success({ success: true }) {
case Success(obj) if (obj.success): trace('yes!');
case Success(obj) if (!obj.success): trace('no!');
case Failure(_): trace('no!');
};
}
}
```

That's fair enough, because guards can be arbitrarily complex.

Consequently, the following should be considered non-exhaustive for the same reasons, but [it compiles just fine](https://try.haxe.org/#64b65) even though it doesn't match:

```haxe
using tink.CoreApi;

class Test {
static function main() {
switch Success({ success: true }) {
case Success({ success: false }): trace('no!');
case Success(obj) if (!obj.success): trace('no!');
case Failure(_): trace('no!');
};
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.