Open
Description
reproduction steps
using Scala 2.13.3
trait A {
self: AnyRef =>
type T = Nothing
def test: T = throw new NotImplementedError
}
trait B extends A {
self: AnyRef =>
override type T = String
override def test: T = "test"
}
class C extends B {
self: AnyRef =>
}
val c: A = new C
problem
This code compiles despite type safety having been compromised. (It does not compile without self-types.) At runtime c.test
throws java.lang.ClassCastException: java.lang.String cannot be cast to scala.runtime.Nothing$
.