-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Clarify what methods are on Null and bottom #28430
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
Comments
Assigning to @lrhn since you wrote up the initial spec - please assign back to me if you'd prefer me to take this. |
For what it's worth, I think my preference is to treat When and if we add We could consider in the meantime treating |
The idea behind the spec documentation (for Dart 1) is that For subtyping and assignability, As for substitutability, nullability is inherently unsafe. List<int> l = new List<Null>();
l[0].abs(); example looks unsafe because it is. But so is: List<int> l = ... anything ...;
int x = l[0];
x.abs(); The For: Future<Null> dontUseMyResult f = ...;
dontUseMyResult.then((n) => n.abs()); // No warnings? Definitely warnings. The static type of To be clear: You can think of it as having nullable types in the language, and when you write Then we do unsafe things like calling For the bottom type, I'm less definite. It exists - the spec mentions it and defines |
Sounds good to me - I think this matches my preferences as well. Does this need to be clarified in the spec, or do you feel it's already implied? It wasn't clear to me reading through it that this was the intended interpretation, for what it's worth. |
SGTM too. |
I think the spec is correct wrt. the explanation above, but for clarity, I might add some commentary (https://codereview.chromium.org/2641873003/).
I don't want to elaborate too much on "nullable types" before we actually add them. There might be a few other edge cases that we need to consider (like in an async function, a plain |
Issue #28024 tracks moving Null to the bottom of the type hierarchy. We need to clarify in the specification what methods are available on the
Null
type (and thebottom
type if the answer is different).The natural answer based on a substitutability principle is that all methods should be allowed to be called on
Null
, and this has been the de facto interpretation of the current Dart spec forbottom
(even though it does not make this explicit).A substitution principle suggests that replacing
l
with its definition should still be well-typed.This is not definitive though. We can certainly choose to provide stronger checking, and it's not clear that there are practical reasons not to. There are certainly good reasons to do the stronger checking. The use of
Future<Null>
to indicate aFuture
whose value should not be used is very suggestive. We would lose substantial static checking if all uses of the result of aFuture<Null>
became valid.cc @floitschG @lrhn @eernstg @munificent @scheglov @bwilkerson @stereotype441
The text was updated successfully, but these errors were encountered: