The following code demonstrates it clearly:
trait Poly1Group[-IUB, +OUB] {
trait Case[-I <: IUB] {
type Out <: OUB // <------------------------------- success
def apply(v: I): Out
}
trait ==>[
-I <: IUB,
O <: OUB //<------------------------------------- fail
] extends Case[I] {
final type Out = O
}
def apply[I <: IUB](v: I)(implicit ev: Case[I]): ev.Out = ev(v)
}
It should be noted that both Out and O are invariant, so they should impose no constraint on the variance of OUB. Yet one succeed and one fails:
[Error] .../Poly1Group.scala:16: covariant type OUB occurs in contravariant position in type <: OUB of type O
one error found
How could it be possible?