Do extension types support statically checked variance? #3624
Labels
extension-types
question
Further information is requested
variance
Issues concerned with explicit variance
Thanks to @sgrekhov for raising this issue! Currently, extension types are specified such that it is an error for a type variable declared by an extension type to occur in a non-covariant position in the representation type. This is required for soundness:
This would be a soundness violation because
eNum.func
has static typevoid Function(num)
and run-time typevoid Function(int)
, and the latter is not a subtype of the former. In short, extension types already behave as if they have the modifierout
on every type parameter, because it would otherwise give rise to soundness violations.It seems obvious that this could be generalized such that an upcoming variance feature could be used with extension types. For example:
We would then make it explicit that extension types do admit statically checked variance modifiers, and a type parameter with no such modifier is implicitly
out
(and that subsumes the current compile-time error involving variance).@dart-lang/language-team, WDYT?
The text was updated successfully, but these errors were encountered: