Skip to content

CCE returning AnyVal from concrete method calling super that abstracts over the AnyVal type #12809

Open
@nafg

Description

@nafg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)valueclass

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions