Warum ist Upcasting in diesem Scala-Code erforderlich?
Dies kompiliert:
import scala.collection._
trait Foo[A, +This <: SortedSet[A] with SortedSetLike[A,This]]
extends SortedSetLike[A, This] { this: This =>
def bar: This = (this: SortedSetLike[A,This]).empty
}
Aber wenn der Upcast entfernt wird, kann er nicht kompiliert werden:
import scala.collection._
trait Foo[A, +This <: SortedSet[A] with SortedSetLike[A,This]]
extends SortedSetLike[A, This] { this: This =>
def bar: This = this.empty
}
Warum? Von demextends
Klausel wir wissen, dassFoo
ist einSortedSetLike[A, This]
, also ist der Upcast natürlich gültig - aber zeigt dies nicht, dass der Compiler das Auftreten von Vererbungskonflikten zugelassen hat?