-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Covariant return types for nullable defaults #48205
Comments
You can't express this in Dart. See related discussions at #42947 |
Sorry, I got mixed up and thought about this kind of variance: |
Because You, on the other hand, would like to allow Unfortunately Dart does not support lower type bounds on type parameters, only upper type bounds, while languages like Java and Scala support both lower and upper type bounds. |
So how come the above |
I am not sure I understand the question. Could you clarify which part of the code works as if |
I've understood the mistake while trying to explain it here. |
Note the overlap with dart-lang/language#1674. |
Functions like
E firstWhere(bool test(E element), {E orElse()?})
have an invariantE
return type.Considering the fact that
E
extendsE?
, andorElse
can usefully returnnull
, I suspect acovariantcontravariantT super E
may be a more useful return type. (I'm not sure how to express this in Dart though).What do you think?
The text was updated successfully, but these errors were encountered: