-
Notifications
You must be signed in to change notification settings - Fork 28
SIP-XX Allow Partial Function Literals to be defined with Parentheses #113
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
base: main
Are you sure you want to change the base?
Conversation
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.
Other than my comment on multiple cases inside parentheses I like the proposal. It's already implemented as part of #23821.
) | ||
``` | ||
|
||
Multi-line `case` blocks should work with parens as well, just like multi-line function |
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.
I'd like to push back on this aspect of the proposal (the rest is great!). We do not allow multiple statements between parentheses, and for good reason, since some of the logic around newline insertion/indentation relies on this. For consistency, we should not allow multiple cases either. I see no good reason to allow it. The code does not become clearer if we do.
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.
Agree!
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.
The argument for multiple cases within parens is that curlies are normally needed for multiple sequential semicolon-separated statements, but you can have multiple cases on a single line without semicolons:
foo.map{ case true => 1 case false => 2 }
By that logic, multiple cases aren't really "statements" in the same way e.g. multiple println
s would be, and so it makes sense that they wouldn't need curlies to allow multiple in the same expression
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.
Technically that's a valid argument, but cases are still multiple things that should not be grouped in parens. More reasons why:
-
this looks bad and we should not encourage that style.
-
there are subtle rules on newline insertion and indentation that depend on not being enclosed by parens. They might cause subtle problems here. I don't want to have to think about these problems or fix bugs if they come up.
No description provided.