Open
Description
Compiler version
3.x.x, Tested specifically 3.0.0 and 3.2.2 (via Scastie) and saw the same behavior.
Minimized code
import scala.deriving.Mirror
object Main extends App {
def badWrapper() = {
case class Baz(i: Int)
object Baz { // It seems to have to do with the companion object
val forceInit = 3
summon[Mirror.Of[Baz]] // This causes a stack overflow of the init...
}
Baz.forceInit
}
badWrapper()
}
Output
➜ scala bug2.scala
Exception in thread "main" java.lang.StackOverflowError
at Main$.Main$$$_$Baz$2(bug2.scala:6)
at Main$Baz$3$.<init>(bug2.scala:8)
at Main$.Baz$lzyINIT1$1(bug2.scala:6)
at Main$.Main$$$_$Baz$2(bug2.scala:6)
at Main$Baz$3$.<init>(bug2.scala:8)
at Main$.Baz$lzyINIT1$1(bug2.scala:6)
at Main$.Main$$$_$Baz$2(bug2.scala:6)
Expectation
I would not expect a stack overflow at runtime in this situation. I would expect the summon to occur, and the number 3 to be returned.
The extended example I provided in the scastie link shows that this only seems to occur if the mirror summon happens in a companion object within a method. If you do it in a singleton its fine, or some other case classes' companion object.