-
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
Proposal for non-nullable types #28619
Conversation
Can we put this document someplace other than on an unmerged branch? Unless we have some sort of system for tracking which branches have important information, but shouldn't be merged, then we don't know which branches besides master, dev, and stable are important. |
Yeah, we can figure out some different process for tracking in-progress proposals. At the time that we decided on this, we were actually using GitHub. I guess we'll need to do something different now. |
any update on this? would love better nullability handling like swift/kotlin |
Sorry, no real update. We've been very focused on getting everything onto strong mode and getting Dart 2 shipped. That's a big migration with a lot of breakage, so it's consumed most of our time and most over our user's capacity to absorb breakage. There is still a lot of hope we can get to non-nullable types before too long, but we'll need to rest a bit and give our customers a little breathing room after the migration we've dragged most of them through. For obvious reasons, adding non-nullable types will cause a lot of breakage and migration cost, so we want to be sensitive to user pain tolerance. :) |
Just break everyone's code every other month, that way they get used to the breakage! |
Yes! The beatings will continue until morale improves. |
@munificent can we merge this proposal? |
Oh, wow, I'd completely forgotten that I wrote this up. If you'd like to use this as a starting for non-nullable types, sure. I don't think we want it in this repo, though. Want me to move it over to the language repo? |
This has been superceded by a new proposal. |
This is the living proposal and tracking bug for adding non-nullable types (#22) to Dart. Two important caveats to keep in mind:
We have not committed to shipping this. We may discover that the overall
usability impact is negative and Dart is better without them.
Because this involves breaking changes, it would not ship until Dart 2.0.
Prototype
In order to assess the usability, we're going to do a prototype first to see how it feels to convert a decent chunk of code (include our core libraries) to use non-nullable types.
The prototype lives on this branch: https://github.com/dart-lang/sdk/tree/prototype-nnbd
Implement static checking rules for non-nullable types
?
to define a nullable type.null
or a non-nullable type to a non-nullable parameter.types. (Is
int?
subtype ofnum?
? Isint
it a subtype ofnum?
?)if (c)
,c ? ... : ...
,c && ...
, etc.)Implement analysis rules to work with nullable types
== null
and!= null
in type promotion.is
on nullable and non-nullable types in type promotion.??
in type promotion. If the LHS side is a local variable, it should promote to non-nullable in the RHS.??
expression.as
handles non-nullable types correctly. (In the analyzer.The runtime implementation is a different thing.)
??=
.nonNullable == null
ornonNullable != null
).Convert core libraries to be null-safe
Map[]
to return a nullable value.new List(size)
.Determine which extensions to the proposal we want to try
local variables.
Convert some framework and library code to be null-safe
Convert an application or two to be null-safe
TODO: Which applications?
Once we get far enough through this, we should be able to confidently decide if
non-nullable types are right for Dart. Assuming they are, we move to:
Real implementation
This is a big feature with a lot of moving parts. I don't have a detailed plan
of everything that needs to be done, but I will progressively refine this as we
figure that out. The current plan is:
?
in type annotations. (Non-nullable type annotation syntax #27231)TODO: Fill in more here.