When overriding a method from the self type of a trait the return type is not checked so this compiles:
trait A {
def a: Int
}
trait B { self: A =>
override def a: String = "Well this should not compile"
}
The compile error happens when B is used:
scala> class C extends A with B
<console>:9: error: overriding method a in trait A of type => Int;
method a in trait B of type => String has incompatible type
class C extends A with B
^
The compile error should already happen when defining B as the method overrides nothing.
When overriding a method from the self type of a trait the return type is not checked so this compiles:
The compile error happens when
B
is used:The compile error should already happen when defining
B
as the method overrides nothing.