-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Control Flow Analysis of Aliased Conditions and Discriminants breaks on else statement if condition not strictly boolean #50637
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
Comments
Note that if |
What whzx5byb said. I don't see a bug here either. |
Okay my bad let me change the return type of getSomeData that it can't allow falsey values.
|
@greg-hornby-roam It seems similar to #33878 |
Hm, there are two separate things happening. One is that non-literals after the const someData = true;
if ((test instanceof A || test instanceof B) && someData) {
test; // A | B
} else {
test; // A | B | C
} And the second is that aliasing does behave differently when the truthy if ((test instanceof A || test instanceof B) && true) {
test; // A | B
} else {
test; // C
}
const aliasedCondition = (test instanceof A || test instanceof B) && true;
if (aliasedCondition) {
test; // A | B
} else {
test; // A | B | C
} Pretty weird. |
Only if ((test instanceof A || test instanceof B) && 11) {
test; //expect A | B - passes
} else {
test; //expect C - fails
} |
Bug Report
🔎 Search Terms
Control Flow Analysis of Aliased Conditions and Discriminants
🕗 Version & Regression Information
4.4+
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
the else statement loses it's narrowing because getData is not strictly a boolean it seems.
🙂 Expected behavior
the if/else of getData should behave the same as the if/else of isAOrB
The text was updated successfully, but these errors were encountered: