Reputation: 959
Hi so I have a trait with generics +T and +U.
def test[I >: T, V >: U](e: Traversable[I], f: V)
def test[I >: T, V >: U](e: (Traversable[I], V))
def test[I >: T, V >: U](e: Tuple2[Traversable[I], V])
The first one works fine. The last 2 however both spit out:
type mismatch;
[error] found : (String, Int)
[error] required: (Traversable[?], ?)
Why can scala not infer the types in the 2nd and 3rd examples? What am I missing?
Thanks
Upvotes: 3
Views: 86
Reputation: 51658
This code compiles in Scala 2.12.3 without errors:
trait MyTrait[+T, +U] {
def test[I >: T, V >: U](e: Traversable[I], f: V)
def test1[I >: T, V >: U](e: (Traversable[I], V))
def test2[I >: T, V >: U](e: Tuple2[Traversable[I], V])
}
Upvotes: 0
Reputation: 810
This looks like a compiler bug to me. I don't see a reason why it can convert String
to Traversable
in the first case but not the other two cases.
Upvotes: 1