As the error says, your rejection annotation A is incorrect. You cannot use A in the return type, which is a covariant position. Imagine you had another method in Foo that uses A in the right contravariant position (as an argument):
trait Foo[-A] { ... def foo(a: A): Unit }
Now you can see how this happens:
Foo[-A] means that Foo[X] <: Foo[Y] if X >: Y- the return value may be a subtype of the declared return type
- therefore, if
-A is legal here, compose can return Foo[A1] for some A1 >: A - say
trait X and trait Y extends X { def bar() } - imagine
Foo[Y] where Foo calls a.bar() - therefore, it will break if
compose allowed to return Foo[X]
So, for an example to compile, A must be invariant.
source share