BoxedUnit cannot be cast to class scala.Function0
See original GitHub issueCompiler 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 ()
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Cannot be cast to class scala.runtime.BoxedUnit - Community
Hi! I encountered an unexpected behavior at runtime. Consider the following code: def execute[R](): R = (new Object).asInstanceOf[R] val r1: Unit ...
Read more >Cast BoxedUnit to scala tuple - apache spark - Stack Overflow
Hello everybody i have an error during running my spark scala code . it says java.lang. ... BoxedUnit cannot be cast to scala.Tuple4....
Read more >scala.runtime.BoxedUnit Java Examples - ProgramCreek.com
This page shows Java code examples of scala.runtime.BoxedUnit.
Read more >Scala callbacks in Kotlin - Alexey Soshin - Medium
data class KotlinClosable ( ... Scala's Function0 is not Kotlin's Function0 , nor Scala's Unit is Kotlin's Unit ... BoxedUnit cannot be cast...
Read more >Java Examples for scala.runtime.BoxedUnit - Javatips.net
This java examples will help you to understand the usage of scala.runtime.BoxedUnit. These source code samples ... BoxedUnit.class); kryo.register(scala.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I confirmed it also compiles under separate compilation, so I’ll try to see what’s wrong with REPL.
It only happens in the repl of main as far as I can see. The following program works as expected: