-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Disallow bad comma left operands #10877
Disallow bad comma left operands #10877
Conversation
baselines needs updating. |
case SyntaxKind.NonNullExpression: | ||
return true; | ||
|
||
case SyntaxKind.ConditionalExpression: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about the condition
part? it could have side effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could, but that's not germane -- [((x++ ? 3 : 4), 7), 3]
is still not a plausibly-correct expression. If both the true
and false
expressions don't have side effects, there's no reason to be using the ?
operator
👍 |
🐌 Travis 🐌 |
👍 |
Fixes #10814
This PR disallows the left operand of the comma operator to be an expression form whose evaluation is known to not have side effects. The
allowUnreachableCode
option suppresses this warning, as does the unaryvoid
operator.The check for "might have side effects" is shallow, which might be considered surprising. The intuition here is that
is not made valid by the side effect inside the unused array literal.