-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow single-line lambdas after :
#23821
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
Will it also work for self types? trait Foo: self =>
end Foo |
I wonder if |
The case for |
If we need a SIP for this, maybe we could fold it into https://contributors.scala-lang.org/t/sip-xx-allow-partial-function-literals-to-be-defined-with-parentheses/7207/16 |
Yes, I think the two go well together. This PR now also implements the single-case version of sip-xx. I have some reservations against admitting multiple cases between parentheses. I'll explain more on the SIP. |
Right now, no. I'd like to re-think self types in general. So I'm not keen on fiddling with them until that's done. |
Previously, we need to indent after the error, e.g. ```scala xs.map: x => x + 1 ``` We now also allow to write the lambda on a single line: ```scala xs.map: x => x + 1 ``` The lambda extends to the end of the line.
Awesome. Will this extend to lambdas with by-name parameters and/or context parameters? You can currently write // after delay, execute fn
def delay(ms: Double)(fn: => Unit) = ???
delay(300):
println("hello") Will we also be able to write def delay(ms: Double)(fn: => Unit) = ???
delay(300): println("hello") and def delay(ms: Double)(fn: (timestamp : Double) ?=> Unit) = ???
delay(300): println(s"time ${timestamp}") ? |
b8b6a68
to
e4a53c6
Compare
Currently, no. We should discuss what we want. Some choices:
Possible reason for (2): The situation is similar to single-line-lambdas with parameters. |
If we allow |
Sorry I might be missing something, why would we have to allow |
Sure, If you don't like |
@lihaoyi Yes, indeed. Allowing arbitrary expressions after |
I believe we have a problem with the new build. It does not pick up the scala-library changes in the bootstrapped build.
Yet, |
e4a53c6
to
07611bf
Compare
@@ -1,6 +1,6 @@ | |||
//> using options -rewrite -indent | |||
//> nominally using scala 3.7.0-RC1 | |||
// does not reproduce under "vulpix" test rig, which enforces certain flag sets? |
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 reproduction was a parser crash instead of (some) error (only under -rewrite
).
I haven't looked yet, but I wonder if it is worth trying to preserve the migration help (in 2025 almost '26)
parentheses are required around the parameter of a lambda
They can use copilot.
Previously, we need to indent after the arrow, e.g.
We now also allow to write the lambda on a single line:
The lambda extends to the end of the line.
This is a trial balloon to see whether anything breaks. If we want to pursue this it needs a SIP.