Closed
Description
Compiler version
3.4.1
Minimized code
It is important to apply each of the definitions/expressions one by one, otherwise the exception is not reproducible.
scala> def g1(acc: Int)(h: (Int, Int) => Int): Int = h(acc, acc)
// def g1(acc: Int)(h: (Int, Int) => Int): Int
scala> def g2(acc: Int)(h: (=> Int, => Int) => Int): Int = h(acc, acc)
// def g2(acc: => Int)(h: (=> Int, => Int) => Int): Int
scala> g2(1)(_ + _)
// java.lang.ClassCastException: class java.lang.Integer cannot be cast to class scala.Function0 (java.lang.Integer is in module
// java.base of loader 'bootstrap'; scala.Function0 is in unnamed module of loader java.net.URLClassLoader @49798e84)
// at scala.Function2.apply$mcIII$sp(Function2.scala:40)
// at rs$line$2$.g2(rs$line$2:1)
// ... 35 elided
Expectation
The result should be 2, instead of a ClassCastException being thrown.
Related IntelliJ IDEA ticket: https://youtrack.jetbrains.com/issue/SCL-22382/ClassNotFoundException-when-running-a-Scala-3-worksheet