Understaing Abstract types

81 views Asked by At

I have the following classes:

abstract class Base {
  type T
  def myMethod: T
}

abstract class B extends Base {
  type T <: String
}

abstract class C extends Base {
  type T <: Int
}

Now, if i write this:

class Test{
    self: B with C => 
    // do sth with myMethod
}

myMethod will result in sth of type Int. If, on the other hand, I write this:

class Test{
    self: C with B => 
    // do sth with myMethod
}

I will get type String. Can someone explain that?

1

There are 1 answers

0
Travis Brown On BEST ANSWER

Yes, I can! It's a bug! And it's the result of "a fundamental problem in Scala's type system" according to Martin Odersky himself (see the comments on that issue for discussion, and also this question from earlier this morning).