Closed
Description
Compiler version
- 3.3.3
- 3.3.4 LTS
- 3.5.2 Next
Minimized code
def fn2(arg: String, arg2: String)(f: String => Unit): Unit =
f(arg)
// doesn't compile
fn2(
arg = "blue sleeps faster than tuesday",
arg2 = "the quick brown fox jumped over the lazy dog"): env =>
val x = env
println(x)
// does compile
fn2(
arg = "blue sleeps faster than tuesday",
arg2 = "the quick brown fox jumped over the lazy dog"):
env =>
val x = env
println(x)
// does compile
fn2(
arg = "blue sleeps faster than tuesday",
arg2 = "the quick brown fox jumped over the lazy dog"
): env =>
val x = env
println(x)
Output
scastie marks two errors:
fn2
line withnot a legal formal parameter for a function literal
val x = env
line withNot found: env
Expectation
According to the documentation, the first argument clause (with arg
and arg2
) does not start an indentation region, hence as long as the lambda body is indented relative to fn2
invocation, it should work.
- https://dotty.epfl.ch/docs/reference/other-new-features/indentation.html#optional-braces-3
- https://dotty.epfl.ch/docs/reference/other-new-features/indentation.html#indentation-and-braces-1
P.S. The problem was first reported in scalameta/scalafmt#4569.