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

Disallow bad comma left operands #10877

Merged
merged 10 commits into from
Sep 14, 2016

Conversation

RyanCavanaugh
Copy link
Member

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 unary void operator.

The check for "might have side effects" is shallow, which might be considered surprising. The intuition here is that

let y = 0;
let x = ([1, 2, y++], 4);

is not made valid by the side effect inside the unused array literal.

@RyanCavanaugh RyanCavanaugh changed the title Disallow bad commas Disallow bad comma left operands Sep 12, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Sep 13, 2016

baselines needs updating.

case SyntaxKind.NonNullExpression:
return true;

case SyntaxKind.ConditionalExpression:
Copy link
Contributor

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.

Copy link
Member Author

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

@mhegazy
Copy link
Contributor

mhegazy commented Sep 13, 2016

👍

@RyanCavanaugh
Copy link
Member Author

🐌 Travis 🐌

@vladima
Copy link
Contributor

vladima commented Sep 13, 2016

👍

@RyanCavanaugh RyanCavanaugh merged commit 4e46b97 into microsoft:master Sep 14, 2016
@RyanCavanaugh RyanCavanaugh deleted the disallowBadCommas branch September 14, 2016 18:19
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants