Skip to content

Excess { required when using polymorphic function lambdas #12277

Closed
@scf37

Description

@scf37

Compiler version

3.0.0-RC3

Minimized code

  def foo(f: => () => Unit): Unit = ???
  def boo(f: [A] => () => Unit): Unit = ???

  foo { () =>  // okay
    println(1)
    println(2)
  }

  boo { [A] => () => // error
    println(1)
    println(2)
  }

  boo { [A] => () => { // okay
    println(1)
    println(2)
  }}

Output

A pure expression does nothing in statement position; you may be omitting necessary parentheses [194:13]
Found:    Unit
Required: PolyFunction{apply: [A](): Unit} [196:12]

Expectation

Same lightweight syntax for polymorphic functions as for "standard" functions
Also by-name parameter support for polymorphic functions could be useful for even clearer syntax.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions