(Scala 2.11.8)
Consider the following snippet:
class Case2 {
trait Container[+A] {
def addAll[B >: A, T2 <: Container[B]](that: T2): Boolean
}
def t1: Container[String] = ???
def t2: Container[Int] = ???
// Works
t1.addAll[Any, Container[Any]](t2)
// Errors:
//* type mismatch; found : Case2.this.Container[Int] required: T2
//* inferred type arguments [String,Case2.this.Container[Int]] do not conform to method addAll's type parameter bounds [B >: String,T2 <: Case2.this.Container[B]]
t1.addAll(t2)
}
Why can't last addAll
call inference the proper least common supertype?
Created a ticket, which was closed as being "out of scope" Quote by Adriaan Moors:
Type inference does not support bounds that refer to other type parameters.