-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix parenthesization of sequence expressions in callee and function params #1566
Conversation
@@ -389,6 +396,13 @@ impl VisitMut for Fixer<'_> { | |||
} | |||
} | |||
|
|||
fn visit_mut_stmt(&mut self, s: &mut Stmt) { |
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.
This fixes a broken test once I added Context::Callee
to the list of contexts to wrap with parens around a sequence expression. I think a previous statement was setting the context and it wasn't being reset when moving on to the next statement.
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.
Seems like a reasonable fix to me.
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.
Great! Thanks!
@@ -389,6 +396,13 @@ impl VisitMut for Fixer<'_> { | |||
} | |||
} | |||
|
|||
fn visit_mut_stmt(&mut self, s: &mut Stmt) { |
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.
Seems like a reasonable fix to me.
This fixes an issue where parentheses would be removed around sequence expressions when they shouldn't, specifically in the case of a call expression callee, and a default value for a function param.
For example:
was compiling to:
which is a syntax error.
A similar issue was seen with default assignment patterns in parameters. The fix was to ensure the correct context is set when visiting a sequence expression so that parentheses are added when needed. I checked a bunch of other places where commas are allowed and these were the ones I found, but there could be more.