Open
Description
The following program compiles under 2.12.3 but gives a ClassCastException at runtime.
import java.util.Comparator
trait Trait1[T] { def foo(arg: Comparator[T]): String }
trait Trait2[T] extends Trait1[T] { def foo(arg: Comparator[String]): Int = 0 }
class Class1 extends Trait2[String] { }
object Test {
def main(args: Array[String]): Unit = {
val c = new Class1
c.foo(Ordering[String])
val t: Trait1[String] = c
val x: String = t.foo(Ordering[String])
}
}
This is an adaptation of the example in Scala SI 4731.scala. The issue is in response to scala/scala3#3989. The fix for #3989 broke the test case pos/t4731.scala
, and investigation showed that the flagged inheritance is unsound.