Skip to content

AbstractMethodError when implementing method with generic type of different arity #12365

Open
@steinybot

Description

@steinybot

reproduction steps

Initially reported as scala-js/scala-js#4454.

See reproduction here: https://github.com/steinybot/bug-reports/tree/scalajs/non-existent-method

using Scala 2.13.5

trait TwoTypeParam[X, Y]
class OneTypeParam[X] extends TwoTypeParam[X, Any]

trait Parent {
  type L = TwoTypeParam[_, _]
  def childMethod: L
  def parentMethod: Any = childMethod
}

class Child extends Parent {
  override def childMethod: OneTypeParam[_] = ???
}

object Test extends App {
  (new Child).parentMethod
}

problem

This compiles and fails at runtime:

sbt:root> fooJVM/run
[info] Compiling 1 Scala source to C:\Users\sjrdo\Documents\Projets\bug-4454\jvm\target\scala-2.13\classes ...
[info] running Child
[error] (run-main-0) java.lang.AbstractMethodError: Method Child$.childMethod()LTwoTypeParam; is abstract
[error] java.lang.AbstractMethodError: Method Child$.childMethod()LTwoTypeParam; is abstract
[error]         at Child$.childMethod(Main.scala)
[error]         at Parent.parentMethod(Main.scala:14)
[error]         at Parent.parentMethod$(Main.scala:14)
[error]         at Child$.parentMethod(Main.scala:1)
[error]         at Child$.delayedEndpoint$Child$1(Main.scala:5)
[error]         at Child$delayedInit$body.apply(Main.scala:1)
[error]         at scala.Function0.apply$mcV$sp(Function0.scala:39)
[error]         at scala.Function0.apply$mcV$sp$(Function0.scala:39)
[error]         at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
[error]         at scala.App.$anonfun$main$1(App.scala:76)
[error]         at scala.App.$anonfun$main$1$adapted(App.scala:76)
[error]         at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563)
[error]         at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561)
[error]         at scala.collection.AbstractIterable.foreach(Iterable.scala:919)
[error]         at scala.App.main(App.scala:76)
[error]         at scala.App.main$(App.scala:74)
[error]         at Child$.main(Main.scala:1)
[error]         at Child.main(Main.scala)
[error]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error]         at java.lang.reflect.Method.invoke(Method.java:498)
[error] stack trace is suppressed; run last fooJVM / Compile / bgRun for the full output
[error] Nonzero exit code: 1
[error] (fooJVM / Compile / run) Nonzero exit code: 1
[error] Total time: 0 s, completed 18 mars 2021 19:08:03

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions