-
Notifications
You must be signed in to change notification settings - Fork 227
Description
We infer bivariance when it is sound to do so; that is, when a type variable is unused in the body of a class:
class C[T]:
passSince this type variable is unused, any specialization of C is equivalent to any other specialization -- it does not matter how you specialize C. In other words, C is bivariant in T.
So our behavior here is correct. But it is confusing, and not useful. We repeatedly run into issues in our test suite where we accidentally make a class bivariant in a typevar and then tests pass for the wrong reason, or fail unexpectedly, since bivariance is not intuitive (covariance is the intuitive expectation).
We should at least emit a diagnostic when we infer a typevar as bivariant (since it indicates the typevar is useless and could just be removed). And we should probably also go ahead and just infer the typevar as covariant in that case.