-
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
Allow Null
as the upper bound of a type variable?
#33709
Comments
Null
as the upper bound of a type variableNull
as the upper bound of a type variable?
@lrhn, @leafpetersen, do you consider it worthwhile to change the specification in order to allow this? |
My general take is that non-uniformities are bad unless there's a good reason for them. I don't see it as being especially useful, but I see no real reason to disallow it. You can get it indirectly via instantiation, so... I'd say let it fly. If the developer really wants a type variable that can only be |
Why is If we want to change the |
We don't have a proof of In any case, you both dislike the anomaly, so I'll make an adjustment to the spec. |
Created this CL to allow |
We noted in issue #33709 that the language specification prevents usage of `Null` as the bound of a type variable, because that makes the bound a subtype of the type variable itself (which is otherwise a symptom of having a cyclic declaration like `X extends X`). This CL adjusts the wording such that it will be possible to use `Null` (or whatever the denoteable bottom type is called) as a bound. Change-Id: I46a5ce6055f3af322a6b93ac38ca2829ce23a26c Reviewed-on: https://dart-review.googlesource.com/63420 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Closing: As of 4fd0404, the subtype circularity prevention rule in the language specification has be adjusted such that |
We noted in issue dart-lang/sdk#33709 that the language specification prevents usage of `Null` as the bound of a type variable, because that makes the bound a subtype of the type variable itself (which is otherwise a symptom of having a cyclic declaration like `X extends X`). This CL adjusts the wording such that it will be possible to use `Null` (or whatever the denoteable bottom type is called) as a bound. Change-Id: I46a5ce6055f3af322a6b93ac38ca2829ce23a26c Reviewed-on: https://dart-review.googlesource.com/63420 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
The language specification prevents an upper bound of a formal type parameter from being
Null
, becauseNull
is a subtype of all other types, and the circularity prevention verbiage (catching cases like<X extends Y, Y extends X>
) just says:where
static type warning
means compile-time error in Dart 2. A similar situation will emerge with a denotable true bottom typeNothing
, if such a type is introduced, say, in connection with the introduction of non-null types—the important part is simply that the bound cannot be a type which is a subtype of every other type.We could consider this to be an accidental special case, in which case we would want to rephrase the specification.
We could also decide that it is useless to specify an upper bound which is the bottom type, because this implies that the bottom type is the only possible actual type argument, i.e., it implies that this type argument will never carry any useful information. Obviously, we'd then have requests for a lint to get rid of it ;-).
This issue is concerned with making a decision on which way to go on that.
The text was updated successfully, but these errors were encountered: