You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classA<X> {}
typedefF1<XextendsA<X>> =XFunction(X x);
typedefF2<XextendsA<X>> =voidFunction();
voidmain() {
voidfoo(
F1 f1, // Error: Instantiation to bound failed.F2 f2, // Error: Instantiation to bound failed.
) {}
}
The raw types F1 and F2 that are used as parameter types in foo are completed by instantiation to bound, yielding F1<A<dynamic>> and F2<A<dynamic>> respectively.
However, those two types are not well-bounded: The type argument A<dynamic> doesn't satisfy the bound (A<dynamic> is not a subtype of A<A<dynamic>>), so the types are not regular-bounded. They are also not correctly super-bounded, because the type parameter is invariant respectively unused, so the substitution step where extreme types are replaced by the "opposite" type when occurring in a position with the right variance doesn't change anything. So F1 and F2 simply can't be used raw anywhere.
The same type can also not be used explicitly, because it still isn't well-bounded:
classA<X> {}
typedefF1<XextendsA<X>> =XFunction(X x);
typedefF2<XextendsA<X>> =voidFunction();
voidmain() {
voidfoo(
F1<A<dynamic>> f1, // Error: Type not well-bounded.F2<A<dynamic>> f2, // Error: Type not well-bounded.
) {}
}
However, dart from commit de3779e does not report any of these errors, so it seems that there is a missing check for such types being well-bounded (or the check occurs, but it replaces dynamic by Null/Never even when it occurs in a position that isn't covariant).
The text was updated successfully, but these errors were encountered:
With the spec update in dart-lang/language#1133, in code with null safety, the compile-time errors described above are no longer errors, because invariant and unused type variables are treated the same as covariant type parameters.
At this point we do not introduce breaking changes for code without null safety.
Consider the following program:
The raw types
F1
andF2
that are used as parameter types infoo
are completed by instantiation to bound, yieldingF1<A<dynamic>>
andF2<A<dynamic>>
respectively.However, those two types are not well-bounded: The type argument
A<dynamic>
doesn't satisfy the bound (A<dynamic>
is not a subtype ofA<A<dynamic>>
), so the types are not regular-bounded. They are also not correctly super-bounded, because the type parameter is invariant respectively unused, so the substitution step where extreme types are replaced by the "opposite" type when occurring in a position with the right variance doesn't change anything. SoF1
andF2
simply can't be used raw anywhere.The same type can also not be used explicitly, because it still isn't well-bounded:
However,
dart
from commit de3779e does not report any of these errors, so it seems that there is a missing check for such types being well-bounded (or the check occurs, but it replacesdynamic
byNull
/Never
even when it occurs in a position that isn't covariant).The text was updated successfully, but these errors were encountered: