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

Change fewerBraces to support inline lambdas after : #15258

Closed
wants to merge 8 commits into from

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 21, 2022

So it's

   xs.map: x =>
       x + 1
     .foldLeft: (x, y) =>
       x + y

Now also possible:

   xs.map: x => x + 1
     .foldLeft: (x, y) => x + y

Based on #15273.

This PR was reworked to show the delta over #15273 needed to support inline lambdas. Before merging it we should decide whether inline lambdas are a good idea.

Instead of parsing all formal parameters of a lambda as expressions
and converting to parameters at the end, we now scan ahead the first time
we see a `:` to determine whether the list is followed by `=>` or `?=>`.
If that's the case we parse this parameter and all following ones as
bindings instead of expressions.
@odersky odersky force-pushed the change-fewerbraces-2 branch 4 times, most recently from 9f61741 to 8f82a28 Compare May 22, 2022 10:39
@odersky odersky changed the title Change fewerbraces 2 Change fewerBraces to always require a :. May 22, 2022
Previously the parser accepted `(x: A => B)` as an expression, but
only if there were parentheses around it. This was necessary so that
we could parse a potential formal parameter of a closure `(x: A => B) => ...`
as an expression and then convert to a type. But it is not backed
by the grammar. The grammar requires `x: (A => B)` whether in
parentheses or not.

We now follow the grammar for source versions from 3.2 on.
 - Allow lambda arguments on one line

# Conflicts:
#	compiler/src/dotty/tools/dotc/parsing/Parsers.scala
#	docs/_docs/internals/syntax.md
#	tests/neg/closure-args.scala
#	tests/pos/closure-args.scala
# Conflicts:
#	docs/_docs/reference/experimental/fewer-braces.md
@odersky odersky marked this pull request as draft May 23, 2022 15:39
@odersky odersky changed the title Change fewerBraces to always require a :. Change fewerBraces to support inline lambdas after : May 23, 2022
@pikinier20
Copy link
Contributor

The map example looks for me way better than before.

Regarding the foldLeft example, it accepts two parameter lists and I'm curious how passing two parameter lists with this PR looks like.

@julienrf
Copy link
Collaborator

I think the proximity with type ascription of dependent function types is too close (see also #15273 (comment)).

I don’t think there are any benefits in writing:

xs.map: x => x + 1

Instead of:

xs.map(x => x + 1)

@odersky
Copy link
Contributor Author

odersky commented May 26, 2022

Closed in favor of #15273

@odersky odersky closed this May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants