2

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.

Michael Zajac
  • 55,144
  • 7
  • 113
  • 138
Ricardo
  • 1,175
  • 2
  • 8
  • 11
  • I'm hesitant to say this is a Scala bug, but it seems like something weird is going on here. You can reproduce the problem with lesser code if you remove the extra type parameter from `C`. Strangely, if you change `<: E` to `<: Z`, the error is gone. So perhaps there is something wrong with the `E` floating between `X` and `Z`. Or perhaps its a deficiency with higher-kinded types. – Michael Zajac May 11 '15 at 18:10

0 Answers0