-
-
Notifications
You must be signed in to change notification settings - Fork 657
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
Switch makes if in case an expression #11814
Comments
Another annoying case is: class Main {
static function main() {
final arr = [1];
foo(() -> {
if (Std.random(1) == 0) {
arr.remove(1);
} else { // Int should be Bool
arr.push(1);
}
});
}
static function foo(callback: Dynamic):Void {}
} |
That's not just when unifying against function main() {
final arr = [1];
final foo = () -> {
if (Std.random(1) == 0) {
arr.remove(1);
} else { // Int should be Bool
arr.push(1);
}
};
$type(foo);
foo();
}
|
The compiler tries to find a minimal type between the branches, but there is no minimal type for I don't think there's anything to fix here. It works if one of the branches is |
The first
addEventListener
works, but in the second I wrap the if/elseif in a switch and I get the following error:The if now requires all its branch to unify to Bool despite not being used as an expression,
shown in the third
addEventListener
where I added anelse
with a Bool value and it works.The fourth
addEventListener
has a return after the switch and the error doesn't trigger, but it seems that any statement works.If instead of
addEventListener
I use a function where the argument is typed as(event:js.html.KeyboardEvent)->Void
it works, but withhaxe.Constraints.Function
the error is present.https://try.haxe.org/#5211741D
The text was updated successfully, but these errors were encountered: