Description
Compiler version
3.0.0
Minimized code
This compiles:
val x = Some(10)
def f =
if x.exists(x => x == 10) then
println("Yes")
else
println("No")
But this does not:
val x = Some(10)
def f =
if x.exists
(x => x == 10) then
println("Yes")
else
println("No")
Expectation
Given that Scala 3 allows method calls like this in other contexts:
foo
(arg)
the if x.exists …
in the second example above seems at least intuitively plausible, even though it doesn’t compile. Clarification as to whether or not that latter example should be considered valid would be appreciated. (The New Control Syntax page doesn’t obviously settle the matter.)
My doubt here arises from:
-
whether the newline after the
if x.exists
should terminate theif
condition, as it currently seems to do in Scala 3.0.0; -
or whether the
if
condition should instead be considered to continue up until the followingthen
, the newline before the indented argument tox.exists
being treated as it would be in other contexts.
Interestingly, this does compile:
val x = Some(10)
def f =
if
x.exists
(x => x == 10) then
println("Yes")
else
println("No")
As does:
val x = Some(10)
def f =
if
x.exists
(x => x == 10)
then
println("Yes")
else
println("No")
Note that this question arose in this Scalafmt-related comment.