-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
It is quite common to pass anonymous partial function to higher-order functions (whether they take a PartialFunction or a regular Function1). In that case, there is no explicit parameter to the lambda, which requires the use of : for the fewerBraces mechanism to kick in:
object Test {
def main(args: Array[String]): Unit =
val xs = List((1, "hello"), (true, "bar"), (false, "foo"))
val ys = xs.collect:
case (b: Boolean, s) if b => s
println(ys)
}I suggest that we infer the : in that situation, so that we could write instead:
object Test {
def main(args: Array[String]): Unit =
val xs = List((1, "hello"), (true, "bar"), (false, "foo"))
val ys = xs.collect // note: no ':' here
case (b: Boolean, s) if b => s
println(ys)
}Currently, the above fails to parse:
-- [E040] Syntax Error: tests/run/hello.scala:5:6 ------------------------------
5 | case (b: Boolean, s) if b => s
| ^^^^
| unindent expected, but 'case' found
-- [E040] Syntax Error: tests/run/hello.scala:7:0 ------------------------------
7 |}
|^
|'}' expected, but unindent found
-- [E006] Not Found Error: tests/run/hello.scala:6:12 --------------------------
6 | println(ys)
| ^^
| Not found: ys
|
| longer explanation available when compiling with `-explain`
3 errors found
LPTK, He-Pin, bishabosha, bmeesters, KacperFKorban and 1 more
Metadata
Metadata
Assignees
Labels
No labels