Closed
Description
Compiler version
Current head, i.e., 9585868
with -language:experimental.fewerBraces
Minimized code
object Test {
def main(args: Array[String]): Unit =
val xs = List((1, "hello"), (2, "bar"))
val ys = xs.map (_, str) =>
val len = str.length
len * len
println(ys)
}
Output
-- [E081] Type Error: tests/run/hello.scala:4:21 -------------------------------
4 | val ys = xs.map (_, str) =>
| ^
| Missing parameter type
|
| I could not infer the type of the parameter _$1 of expanded function:
| _$1 =>
| xs.map(
| (_$1, str) =>
| {
| val len = str.length
| len * len
| }
| ).
1 error found
Expectation
I expect it to compile.
Workaround
Giving an (unused) name to the parameter makes it compile and run successfully:
object Test {
def main(args: Array[String]): Unit =
val xs = List((1, "hello"), (2, "bar"))
val ys = xs.map (unused, str) =>
val len = str.length
len * len
println(ys)
}
prints
List(25, 9)