问题
I've narrowed down my issue to the following minimal (non-)working example:
class Z
trait A[E <: Z] { type T[X <: E] <: A[X] }
trait B[E <: Z] extends A[E] { type T[X <: E] <: B[X] }
trait C[E <: Z, F[X <: Z] <: C[X, F]] extends A[E] { type T[X <: E] = F[X] }
class D[E <: Z] extends B[E] with C[E, D]
It is sort of a higher-kinded F-bounded polymorphism (I'm using T[E] as the return value of some methods). When I try to compile this code I get:
error: overriding type T in trait B with bounds[X <: E] <: B[X];
type T in trait C, which equals [X <: E]D[X] has incompatible type
However, given that D
is a sub-type of B
and that the same E
is passed to B
and C
, the types shouldn't be incompatible. Martin Odersky explained in this question that when merging a member in a mixin, there are two rules: 1) concrete over abstract and 2) linearisation order. In this case both are "concrete" types so we go with 2). But the linearisation order says that C
should win over B
, so I'm left wondering what is it that I'm getting wrong here.
来源:https://stackoverflow.com/questions/30118608/scala-overriding-type-member-with-bounds