Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upNull Safety: Sound non-nullable types with incremental migration (NNBD) #110
Comments
This comment has been minimized.
This comment has been minimized.
I've added a draft of the roadmap for this proposal, linked from the header comment. |
This comment has been minimized.
This comment has been minimized.
@jmesserly I'm not sure how to constructively move the NNBD discussion from #125 here, because the my suggestion is all about linking the two issues. But I'll try: I suggest that, as a first step, we introduce sound non-nullable types as part of immutable types (#125). This has several advantages:
|
This comment has been minimized.
This comment has been minimized.
IMO, linking the two proposals would be counterproductive. We are working hard on NNBD, there is a lot of design & planning work going on. There aren't any major open questions on syntax or desired semantics. Linking the two would prevent us from pushing forward on NNBD, because immutable types has a lot of open design questions, and we'd have to delay work on NNBD until that's resolved. (Also it could be confusing if different parts of the language treat |
This comment has been minimized.
This comment has been minimized.
That's fine too, it was just an idea. I don't have enough context to know how best to proceed, so if you believe that NNBD and immutables should proceed completely independently, then they should :) |
This comment has been minimized.
This comment has been minimized.
Makes sense :). Yeah, we seem to be gathering a lot of momentum behind Leaf's proposal. It's really exciting! I think we'll be able to apply the many lessons of Strong Mode to NNBD, to make the migration as easy & rewarding as possible. (e.g. ideally it's non-breaking for code that isn't migrated. Until you turn on NNBD, you don't break. Once you turn it on, you have to fix some errors, but you gain some degree of null safety, even if everything else isn't migrated yet. Once everything in an app is migrated, then it has sound null safety. It's pretty neat.) |
... which in this CL will always null. This is the first step when adding NNDB support as outlined in dart-lang/language#110 Change-Id: If3810bcaf1b73e70924f09d619e2a84e7d5ba8d6 Reviewed-on: https://dart-review.googlesource.com/c/86860 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
This adds code to ignore trailing `?` in `as` and `is` expressions because the trailing `?` may be part of the larger expression. At the moment, this change is a no-op, but will become active when a subsequent CL lands support for nullable types as part of dart-lang/language#110 Change-Id: I829d6aee0f11957ca9b5e143000005031649449f Reviewed-on: https://dart-review.googlesource.com/c/86960 Reviewed-by: Brian Wilkerson <[email protected]>
... as part of adding NNBD as outlined in dart-lang/language#110 This only supports parsing simple nullable types such as int? and List<int>? while subsequent CLs will add support for parsing more complex types. Change-Id: I3cc5c65d20bf3732a39cab0e823b2f7332342866 Reviewed-on: https://dart-review.googlesource.com/c/86961 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
... which in this CL will always null. This is another step when adding NNDB support as outlined in dart-lang/language#110 Change-Id: I3974fcb885c63be4af9d1007258383f3f8191ae0 Reviewed-on: https://dart-review.googlesource.com/c/87080 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
…tion type This only supports nullable return values of the form <identifier> '?' 'Function' '(' ... This is an increment CL in the ongoing effort to add nullable type support as outlined in dart-lang/language#110 Change-Id: I42febae9f88f7e4d8b05907988deab97c7a7425c Reviewed-on: https://dart-review.googlesource.com/c/87081 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
This adds support for nullable types of the form <identifier> '.' <identifier> '?' and <identifier> '.' <identifier> '?' 'Function' '(' ... This is an increment CL in the ongoing effort to add nullable type support as outlined in dart-lang/language#110 Change-Id: I526aecbe64bacbd442cea0b4c52d36ff23b0443b Reviewed-on: https://dart-review.googlesource.com/c/87083 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
This reverts commit 7720689. Reason for revert: Breaks parsing less common conditionals (e.g. b ? c = true : g();) Original change's description: > Add support for prefixed nullable type > > This adds support for nullable types of the form > > <identifier> '.' <identifier> '?' > > and > > <identifier> '.' <identifier> '?' 'Function' '(' ... > > This is an increment CL in the ongoing effort to add nullable type support > as outlined in dart-lang/language#110 > > Change-Id: I526aecbe64bacbd442cea0b4c52d36ff23b0443b > Reviewed-on: https://dart-review.googlesource.com/c/87083 > Reviewed-by: Brian Wilkerson <[email protected]> > Commit-Queue: Dan Rubel <[email protected]> [email protected],[email protected] Change-Id: Ib5e74b4aad239f561a33eae9d95dffa2693037f7 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/87282 Reviewed-by: Dan Rubel <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
…unction type This reverts commit 11d081d Reason for revert: Breaks parsing less common conditionals (e.g. b ? c = true : g();) Original change's description: > Add support for simple nullable type return value in generalized function type > > This only supports nullable return values of the form > > <identifier> '?' 'Function' '(' ... > > This is an increment CL in the ongoing effort to add nullable type support > as outlined in dart-lang/language#110 Change-Id: I99bce29619d4e448193e3c81fa86a982791b1f77 Reviewed-on: https://dart-review.googlesource.com/c/87283 Reviewed-by: Dan Rubel <[email protected]>
This reverts commit bc8c7cf Reason for revert: Breaks parsing less common conditionals (e.g. b ? c = true : g();) Original change's description: > Add support for parsing simple nullable types > > ... as part of adding NNBD as outlined in > dart-lang/language#110 > > This only supports parsing simple nullable types > such as int? and List<int>? while subsequent CLs > will add support for parsing more complex types. Change-Id: I49a21a85dca19241e3b23ed5c9fb6084e70f2000 Reviewed-on: https://dart-review.googlesource.com/c/87284 Reviewed-by: Dan Rubel <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
This comment has been minimized.
This comment has been minimized.
I've updated the header with some sub-issues for discussing specific topics. |
... as part of adding NNBD as outlined in dart-lang/language#110 This only supports parsing simple nullable types such as int? and List<int>? while subsequent CLs will add support for parsing more complex types. Change-Id: I144858946cb115755af437299899c2631105bf8c Reviewed-on: https://dart-review.googlesource.com/c/87501 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
This reverts commit c5fd11b. Reason for revert: Conditional expression lookahead may modify the token stream Original change's description: > Add support for parsing simple nullable types > > ... as part of adding NNBD as outlined in > dart-lang/language#110 > > This only supports parsing simple nullable types > such as int? and List<int>? while subsequent CLs > will add support for parsing more complex types. > > Change-Id: I144858946cb115755af437299899c2631105bf8c > Reviewed-on: https://dart-review.googlesource.com/c/87501 > Reviewed-by: Brian Wilkerson <[email protected]> > Commit-Queue: Dan Rubel <[email protected]> [email protected],[email protected] Change-Id: Ie1f47e7384ff51159aa2ebeb21561455b8e6287f No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/87620 Reviewed-by: Dan Rubel <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
... as part of adding NNBD as outlined in dart-lang/language#110 This CL updates the parser to recognize two specialized comments at the beginning of a library of the form '//@NNBD' and '//@NNBD*' for use by the analyzer to aid developers when converting their libraries to be non-nullable by default. In addition, the AstBuilder now populates the generated analyzer AST with nullable type information. Change-Id: I80d221dd138973aa32f05bde631245d9ac6ee10f Reviewed-on: https://dart-review.googlesource.com/c/87540 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
... as part of adding NNBD as outlined in dart-lang/language#110 This only supports parsing simple nullable types such as int? and List<int>? while subsequent CLs will add support for parsing more complex types. Due to current parser limitations, it also only supports nullable types in a limited number of statements such as T? t; if (x is String?) {} In addition, address comments in * https://dart-review.googlesource.com/c/sdk/+/87880 * https://dart-review.googlesource.com/c/sdk/+/87881 Change-Id: Ife4afadc0b72906fc0c4e9b1977ad838041c2a84 Reviewed-on: https://dart-review.googlesource.com/c/87920 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
This comment has been minimized.
This comment has been minimized.
Added links to two new discussion issues in the header comment. |
This comment has been minimized.
This comment has been minimized.
Is there there any discussion around prototype overload for non nullable types caused by optional parameters? There are a few objects that behaves differently based on whether an optional argument is present or not. One example is StreamBuilder. If
But if omitted, the prototype is:
Similarly, there are a few asserts performed by widgets like |
This comment has been minimized.
This comment has been minimized.
I'm not entirely sure what you mean, but I think the answer is no. This might be more of a question for the flutter framework to answer - how they plan to migrate their API here. We don't have overloading in Dart, and won't get it any time soon. For this API, it looks to me like either you have to either:
|
This comment has been minimized.
This comment has been minimized.
Indentation for NNBBD now works with WebStorm 2019.2. |
This comment has been minimized.
This comment has been minimized.
@leafpetersen I think the question is in general: what if you have two parameters where exactly one is null, but not the other. Usually, you do It would be nice to instead list all possible “variants” of the function signature and bind it to one implementation, like:
|
This comment has been minimized.
This comment has been minimized.
I hear method overloading?
Don’t play with my feelings
… Em 24 de ago de 2019, à(s) 17:14, derolf ***@***.***> escreveu:
Is there there any discussion around prototype overload for non nullable types caused by optional parameters? ...
@leafpetersen <https://github.com/leafpetersen> I think the question is in general: what if you have two parameters where exactly one is null, but not the other.
Usually, you do assert((a == null) != (b == null)).
It would be nice to instead list all possible “variants” of the function signature and bind it to one implementation, like:
void func(int? a, int b),
void func(int a, int? b) {
...
}
|
This comment has been minimized.
This comment has been minimized.
Hi, is there an ETA on non-nullables? Even a very loose one, like tomorrow, 5 months, or 2 years from now. |
This comment has been minimized.
This comment has been minimized.
There's a flag for a preview usually. Here's the flag for static extensions: dart-lang/sdk#37893 (comment) I don't know the flag for nnbd, but it's likely that if you use the 2.5-dev and try to use nnbd syntax, the compiler will tell you to turn on the flag. |
This comment has been minimized.
This comment has been minimized.
The flag is |
This comment has been minimized.
This comment has been minimized.
We're working on that. :) |
This comment has been minimized.
This comment has been minimized.
Yes, thanks, I see that now.
So does anyone have a (relative) idea of when this will be ready, or at least usable? |
This comment has been minimized.
This comment has been minimized.
Yeah, it would be nice. Unfortunately, not at the top of our list of things to tackle right now, sorry! |
This comment has been minimized.
This comment has been minimized.
We really don't want to promise dates yet. Everybody is working full out on this and extension methods right now, it will be ready when it's ready! You can search for NNBD in the sdk issue tracker to get a sense of where things are, and I'll try to update now and then when notable milestones are passed. |
This comment has been minimized.
This comment has been minimized.
Ok, thanks! |
This comment has been minimized.
This comment has been minimized.
Wow, extensions functions are coming as well? That’s really cool. What about let/apply/run-constructs from Kotlin? |
This comment has been minimized.
This comment has been minimized.
For early adopters, is it possible to already run code that utilises the extensions? |
This comment has been minimized.
This comment has been minimized.
Yes, extensions let you define all kinds of members: methods, getters, setters, index operators, operators, etc.
Not yet. We're pretty far along but there's still implementation work left to do. Stay tuned. :) |
This comment has been minimized.
This comment has been minimized.
Is ‘Null’ nullable and is ‘Null’ the same as ‘Never?’. |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Hey, we converted an entire project over the last 3 days to use optionals since without them there's so much possiblity for crashes. Seems we can't compile it to release. Any solutions for this? Some setting to bypass it? |
This comment has been minimized.
This comment has been minimized.
@ollydixon |
This comment has been minimized.
This comment has been minimized.
Any timeline? Even if it's vague |
This is a solution proposal for #71. The proposal will cover both the intended final language design, and the language, tooling, and ecosystem support required for the migration. A roadmap describing the general goals and desired properties of the feature is here. Discussion of specific details of the language design is underway.
All NNBD related issues:
Topic specific discussion issues for resolution:
!
.Object
nullable?T!
?late
await
vs!
!
binds more tightly.late
variables