-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Require the first argument to assert() to be a bool #30326
Comments
What this probably means in practice is to start issuing a hint relatively soon indicating that this feature is obsolete (with a quick fix to add the parentheses). In 2.0 we can promote the hint to an error. |
For google, we're going to want it to be an error sooner, i.e. to prevent slide-back. |
we can have it be an error in strong mode. I'm happy to send CL's to help fix internal code for the Dart SDK roll |
Woohoo! |
Last I heard, hints will also fail the internal build, so I don't think promoting it sooner will be necessary. |
This addresses the type inference part of #30326. R=scheglov@google.com Review-Url: https://codereview.chromium.org/2997513002 .
Dart used to allow the first argument to assert() to be a function, which it would implicitly call, but this is being removed for Dart 2.0. #30326 This gets the test testing the 2.0 behavior. Since the test is now leading the implementation, updated the status files to mark it failing. Bug: #30326 Change-Id: Ia61f540f1991ecdf42ccdb47b932890e636c1bd3 Reviewed-on: https://dart-review.googlesource.com/4181 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
These are not supported in Dart 2.0: #30326 Change-Id: I2e177a647c43af2bf7f37ff382234b12b8c2286c Reviewed-on: https://dart-review.googlesource.com/4182 Reviewed-by: Jennifer Messerly <jmesserly@google.com>
@bwilkerson Let's get on that sooner rather than later. I'm guessing that we can go back to assuming the type of the assert argument is bool? Right, @munificent ? |
DDC in Dart SDK 2.0.0-dev.0.0 removed this feature More to come: dart-lang/sdk#30326
DDC in Dart SDK 2.0.0-dev.0.0 removed this feature More to come: dart-lang/sdk#30326
DDC in Dart SDK 2.0.0-dev.0.0 removed this feature Plans to remove it entirely in Dart 2: dart-lang/sdk#30326 Closes #634 PiperOrigin-RevId: 169286011
DDC in Dart SDK 2.0.0-dev.0.0 removed this feature Plans to remove it entirely in Dart 2: dart-lang/sdk#30326 Closes #634 PiperOrigin-RevId: 169286011
We aren't going back to assuming the type is a bool. It's allowed, effectively, |
This is to prepare for the new language restriction: dart-lang/sdk#30326 PiperOrigin-RevId: 180941194
In Dart 2.0, only boolean values will be accepted by assert. Closures were previously accepted, but should simply self-evaluate now. dart-lang/sdk#30326
This is to prepare for the new language restriction: dart-lang/sdk#30326 PiperOrigin-RevId: 181648657
This is to prepare for the new language restriction: dart-lang/sdk#30326 PiperOrigin-RevId: 181648657
This is to prepare for the new language restriction: dart-lang/sdk#30326 PiperOrigin-RevId: 181648657
This is to prepare for the new language restriction: dart-lang/sdk#30326 PiperOrigin-RevId: 181648657
This is to prepare for the new language restriction: dart-lang/sdk#30326 PiperOrigin-RevId: 181648657
This is to prepare for the new language restriction: dart-lang/sdk#30326 PiperOrigin-RevId: 180941194
In Dart 2.0, assert will only accept booleans, not closures any more. The solution to upgrade is very simple: we just self-execute any closures passed to assert today. dart-lang/sdk#30326 PiperOrigin-RevId: 183011076
In Dart 2.0, assert will only accept booleans, not closures any more. The solution to upgrade is very simple: we just self-execute any closures passed to assert today. dart-lang/sdk#30326 PiperOrigin-RevId: 183011076
Support removed from analyzer in https://dart-review.googlesource.com/c/sdk/+/31963. All internal usage is fixed. |
Also, I think some flutter testing this week revealed that closures-in-bool has been removed (was never written) in front-end. |
Front end gives an error, as does the VM in preview-dart-2. The analyzer also gives an error now in strong mode. I believe that all of the code that we need to/plan to clean up is clean. |
Is any work actually remaining here for Dart 2? |
I guess that's just a question for dart2js, according to the checkboxes. |
dart2js is derived from the CFE in this case, so no action needed on our end. I just marked the checkbox. |
I think that covers it. |
The language currently allows the first argument to
assert()
to be either a bool, or a nullary function that returns a bool when called. In the latter case, it is implicitly invoked:That only adds the tiniest bit of syntactic sugar. Without this feature, you could always just call the function yourself:
In return for saving you a
()
, the type inference forassert()
isn't as useful as it could be. It can't assume that the first argument should be a bool when performing downwards type inference.There is also, of course, the implementation complexity and cognitive overhead of this obscure feature. It doesn't carry its weight, so the language team has decided to remove it for Dart 2.0.
In 2.0, the first argument to
assert()
must be an expression that evaluates totrue
orfalse
. You can migrate your existing using of the removed feature by adding a()
after your function.We still need to figure out what tasks are required to ship this, but to get started:
assert()
tests. (https://dart-review.googlesource.com/c/sdk/+/4181)The text was updated successfully, but these errors were encountered: