Skip to content

Wildcard type parameter causes java.lang.AbstractMethodError #10363

@ocadaruma

Description

@ocadaruma

I tried following snippet on REPL.

trait Foo[A, B]
object Foo {
  type Bar[A] = Foo[A, _]
}

trait Base[M[_]] {
  def method(in: M[_]): Unit
}

class Concrete extends Base[Foo.Bar] {
  def method(in: Foo.Bar[_]): Unit = {}
}

trait Template[M[_]] {
  def toBeImplemented: Base[M]
  def mark[A]: M[A]

  def method2(): Unit = {
    toBeImplemented.method(mark[Nothing])
  }
}

class Impl extends Template[Foo.Bar] {
  def toBeImplemented: Base[Foo.Bar] = new Concrete
  def mark[A]: Foo.Bar[A] = new Foo[A, Nothing] {}
}

(new Impl).method2()

This compiles and causes java.lang.AbstractMethodError: Concrete.method(Ljava/lang/Object;)V .

However, If I change type Bar[A] = Foo[A, _] to type Bar[A] = Foo[A, Nothing], the snippet run successfully. (no error occured)

I think the first snippet should not compile.

environment

  • Scala version: 2.11.8 and 2.12.2
  • Java version: 1.8.0_77

possibly related

#8681, #10345

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions