Open
Description
Compiler version
Minimized code
Welcome to Scala 3.1.3-RC1-bin-SNAPSHOT-git-d38e10e (17.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> def g(args: Int*)(block: => Unit): Unit = println(s"Well, ${args.sum} and $block")
def g(args: Int*)(block: => Unit): Unit
scala> def f = g()
def f: (=> Unit) => Unit
scala> f(println("x"))
x
java.lang.ClassCastException: class scala.runtime.BoxedUnit cannot be cast to class scala.Function0 (scala.runtime.BoxedUnit and scala.Function0 are in unnamed module of loader java.net.URLClassLoader @535b8c24)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
... 33 elided
Expectation
Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 17.0.2).
Type in expressions for evaluation. Or try :help.
scala> def g(args: Int*)(block: => Unit): Unit = println(s"Well, ${args.sum} and $block")
def g(args: Int*)(block: => Unit): Unit
scala> def f = g()
^
error: missing argument list for method g
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `g _` or `g(_)(_)` instead of `g`.
scala> def f = g() _
def f: (=> Unit) => Unit
scala> f(println("x"))
x
Well, 0 and ()