Allow single-line lambdas after :#23821
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. |
|
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.
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 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.
07611bf to
007c4de
Compare
|
This was accepted as ready or implementation in the SIP meeting of Oct 24th, 2025. |
|
No new regressions found in the OpenCB when comparing against current main |
Co-authored-by: Oliver Bračevac <bracevac@users.noreply.github.com>
Backports #23821 to the 3.8.0-RC1. PR submitted by the release tooling. [skip ci]
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.