-
Notifications
You must be signed in to change notification settings - Fork 1.7k
can't assert "== null" in an initializer assert (but != null works) #30288
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
Are you using the --assert_initializer option. I tried this on TOT command line dart VM and it seems to work : main() sivalinuxmach[sdk]>out/ReleaseX64/dart --checked --assert_initializer /tmp/junk.dart |
Sorry, I should have been explicit. This is an analyzer failure, not a VM failure. |
Thanks somebody marked it under area-vm, will change accordingly. |
* PopupMenuButton: create IconButton if child is Icon Otherwise the resulting button has an abnormally small and rectangular area. With multiple PopupMenuButton(child: Icon) they get squished together in the AppBar. * Add separate icon argument to PopupMenuButton * Fix style issues and tweak dartdocs * Add tests for icon argument to PopupMenuButton * Group icon tests and fix broken test, analyzer warnings * Test that the correct custom icon is present * Apply De Morgan's to work around dart analyzer bug see: dart-lang/sdk#30288
@lrhn I have a question about the specification, and I'm hoping you can answer it. In section 16.1 it says:
Given the code above, I would expect analyzer to figure out that Is that your interpretation, or am I wrong here? |
Constant evaluation is all about objects, not static types. That's why the VM has been able to implement it without having a static type system. The potentially constant vs actually compile-time constant distinction is a little tricky in the spec. The expression When you do evaluate the const constructor call, you evaluate the expression as a compile-time constant expression as if the parameters were const variables with the provided values. So, it's a valid potentially constant expression and evaluation as compile-time constant expression succeeds. It would succeed no matter which arguments were passed. It would not succeed if the arguments were non-int/string/bool/null values, because then the expression To get around that, you can use (And yes, the |
PS: As of f11f2ed, the spec has been modified to lift the non-int/string/bool/null restriction. Here's the updated constant expression case:
So the tools should allow it, plain |
See also #29278 which is about allowing enums in these expressions. |
Tooling is allowing Fails: class Test2 {
const Test2({this.opt1, this.opt2}) : assert(opt1 == null || opt2 == null);
final Object opt1;
final Object opt2;
} Passes: class Test2 {
const Test2({this.opt1, this.opt2}) : assert(identical(opt1, null) || identical(opt2, null));
final Object opt1;
final Object opt2;
} |
...results in:
...but this works fine:
The text was updated successfully, but these errors were encountered: