« Return to Thread: [scala] Bounds on abstract types

[scala] Bounds on abstract types

by nikov :: Rate this Message:

Reply to Author | View in Thread

Hi,

Consider this code:

////////////////////////////////////////
trait A {
  type T <: this.type with C
}

trait B extends A {
  type T <: this.type with C
}

trait C extends B {
  type T <: this.type with C
}
////////////////////////////////////////

Scala compiler rejects it:

<console>:11: error: overriding type T in trait B with bounds >:
Nothing <: C.this.type with C;
 type T has incompatible type
         type T <: this.type with C
              ^

But the following is accepted:

////////////////////////////////////////
trait A {
  type T <: this.type with C
}

trait B extends A {
  type T <: this.type with C
}

trait C extends B {
}
////////////////////////////////////////

Can anybody explain, why?

Thanks,
Vladimir

 « Return to Thread: [scala] Bounds on abstract types