Open
Description
Reproduction steps
Scala version: Scala 2, including 2.13.11, but going way back too
Tested on JVM and JS. Confirmed it works on Scala 3 (both)
Code is at https://github.com/nafg/reproduce-anyval-cce
class Inner
class Outer(val inner: Inner) extends AnyVal
trait Abstract[F] {
protected def helper: F
protected def method(): F = helper
}
trait Concrete extends Abstract[Outer] {
override protected def helper: Outer = new Outer(new Inner())
}
trait Public extends Concrete {
def method2(): Outer = super.method()
}
object instance extends Public
instance.method2()
This is a minimized version of a real world problem. I discussed it at https://discord.com/channels/632150470000902164/635668814956068864/1119201503937302610
Translation:
Name in minimized | Real symbol |
---|---|
Inner |
japgolly.scalajs.react.callback.Trampoline |
Outer |
japgolly.scalajs.react.callback.CallbackTo |
Abstract |
japgolly.scalajs.react.extra.BroadcasterF |
Abstract#helper |
japgolly.scalajs.react.util.Effect.UnsafeSync#traverse_ |
Abstract#method |
japgolly.scalajs.react.extra.BroadcasterF#broadcast |
Concrete |
japgolly.scalajs.react.extra.Broadcaster |
Concrete#helper |
japgolly.scalajs.react.util.EffectCallback.callback#traverse_ |
Public |
io.github.nafg.scalajs.react.util.PublicBroadcaster |
Problem
It crashes at runtime with Exception in thread "main" java.lang.ClassCastException: class Outer cannot be cast to class Inner
Note that removing super.
in method2
fixes it. Originally I was overriding the same method just to make it public.