Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fewerBraces lambdas cannot have _ arguments #15082

Closed
sjrd opened this issue May 2, 2022 · 1 comment · Fixed by #15273
Closed

fewerBraces lambdas cannot have _ arguments #15082

sjrd opened this issue May 2, 2022 · 1 comment · Fixed by #15273
Assignees
Milestone

Comments

@sjrd
Copy link
Member

sjrd commented May 2, 2022

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)
@sjrd sjrd added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 2, 2022
@mbovel mbovel added area:parser and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 3, 2022
@odersky
Copy link
Contributor

odersky commented May 26, 2022

Fixed in #15273

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants