Skip to content

Conversation

lihaoyi
Copy link
Contributor

@lihaoyi lihaoyi commented Aug 22, 2025

No description provided.

Copy link
Contributor

@odersky odersky left a 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
Copy link
Contributor

@odersky odersky Aug 29, 2025

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree!

Copy link
Contributor Author

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 printlns would be, and so it makes sense that they wouldn't need curlies to allow multiple in the same expression

Copy link
Contributor

@odersky odersky Aug 30, 2025

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.

@bracevac bracevac changed the title SIP-XX Allow Partial Function Literals to be defined with Parentheses SIP-74 Allow Partial Function Literals to be defined with Parentheses Sep 26, 2025
@bracevac bracevac requested a review from smarter September 26, 2025 15:01
@odersky
Copy link
Contributor

odersky commented Sep 26, 2025

For the case of single cases inside parentheses or at the top-level the syntax change is one line in the production of Expr. This is currently:

Expr              ::=  FunParams (‘=>’ | ‘?=>’) Expr  
                    |  TypTypeParamClause ‘=>’ Expr     
                    |  Expr1 

The SIP adds one more alternative:

Expr             ::= ...
                   |  ExprCaseClause           

ExprCaseClause already exists, it is defined like this:

ExprCaseClause    ::=  ‘case’ Pattern [Guard] ‘=>’ Expr

Maybe this can be integrated in the SIP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants