Open
Description
trait Stuff[A]
def take[A](st: Stuff[A]): Stuff[A] = st
take(??? : Stuff[Nothing])
Result:
<console>:13: error: type mismatch;
found : Stuff[Nothing]
required: Stuff[A]
Note: Nothing <: A, but trait Stuff is invariant in type A.
You may wish to define A as +A instead. (SLS 4.5)
take(??? : Stuff[Nothing])
^
The error goes away if either:
- type parameter is explicit (i.e.
take[Nothing](??? : Stuff[Nothing])
) A
is covariantA
occurs in covariant position in return type oftake
or does not occur at all
Original SO question: http://stackoverflow.com/questions/32097291/bizzare-type-inference-limitation-multiple-type-params