Given the following code:
class A {
class B
type C <: B
trait D
}
class E extends A {
type C = B
}
class F extends E {
override type C = B with D
}
Why does the Scala IDE's presentation compiler within the Eclipse Indigo IDE complain with the error message overriding type C in class E, which equals F.this.B; type C has incompatible type?
After all class "B" is only "amended" with trait "D" and thus the two type definitions are of the same base type, which is "B". Hence compatible type definitions.
The code below works. I consider the rules for type assignment similiar to variable assignment, such as:
class Foo
trait Bar
val a: Foo = new Foo
val fooWithBar: Foo = new Foo with Bar
Is my understanding wrong?
They are not compatible, type C might be used in a contravariant position
Complement given
e: E
, you are allowed to calle.f(new B)
. What ife
wasval e = new F
?