-
Notifications
You must be signed in to change notification settings - Fork 207
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
Promotion based on a non-null test: Implementation more flexible than specification #2258
Comments
@stereotype441 @johnniwinther might be useful to start with a short explanation of what the implementation is doing? |
Yeah, that spec language doesn't adequately capture what the implementations are doing. The key implementation methods are the The front end implementation of // NonNull(X) = X & NonNull(B), where B is the bound of X.
//
// NonNull(X & T) = X & NonNull(T)
//
// NonNull(T?) = NonNull(T)
//
// NonNull(T*) = NonNull(T) So, for the example above, the test I think the
This change would also address two other problems with that spec text you quoted:
|
@leafpetersen and @stereotype441, here's the proposed updated text in the specification (a PR that introduces new sections about null safety):
Note that this section is just a placeholder which is intended to give a brief, informal overview of the type promotion mechanism in Dart. It is needed because we used to have a short section on type promotion, and that section is being removed as part of the null safety updates, and it is useful to have a place for the references to point to (and it seems fair to give the reader just an informal section rather than nothing). So it's not fully formal, and it only covers a couple of special cases. In any case, comments about things to improve would be welcome, of course! |
Consider the following declaration:
This program is accepted by the analyzer as well as the CFE (DartPad, 'Based on Flutter 3.0.1 Dart SDK 2.17.1'), and it illustrates that the test
x != null
can promote a variable fromX & int?
toX & int
.The specification language for this case would be the following:
However, that rule only handles the case where the variable has a type of the form
T?
, andX & int?
is not such a type. Do we need to generalize the specification a little bit in order to describe what the tools are currently doing?@leafpetersen, WDYT?
The text was updated successfully, but these errors were encountered: