-
Notifications
You must be signed in to change notification settings - Fork 1.7k
const asserts with == null
#31140
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
This restriction comes directly from the language spec. I think the spec would need to be updated before we could update analyzer, so I'm marking this as a language issue. |
Seems like a bug/oversight in the specification. I'm sympathetic to fixing it. |
Dup of #30288 ? |
…m/string/bool/null. See issue #31140 Bug: http://dartbug.com/31140 Change-Id: I141cc3856a1758313de102084f74f4fa41412586 Reviewed-on: https://dart-review.googlesource.com/15100 Commit-Queue: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
The example no longer reports an error:
|
If I try to revert our workaround for this and use
|
Issue is definitely still here. The problem does not occur in the test above because the constructor is never called with an object which isn't of those types. |
FWIW this issue affects Hummingbird. We have to comment out some asserts to make the code run in DDC. |
I think analyzer 2.5.0, with the const-update-2018, produces the correct behavior. Using the example above: class Foo {
const Foo({ this.child, this.text }) : assert(child == null || text == null);
final Widget child;
final String text;
}
class Widget {
const Widget();
}
void main() {
const Foo(child: null, text: null);
const Foo(child: null, text: 'yay');
const Foo(child: const Widget(), text: null);
const Foo(child: const Widget(), text: 'yay');
} The analyzer only reports an error on the last line:
|
We merged into the main Flutter repo and that repo passes the analyzer, so I guess this is fixed. |
The following code produces the analyzer error "In constant expressions, operands of this operator must be of type 'bool', 'num', 'String' or 'null'. (const_eval_type_bool_num_string)" on the
child == null
part.Seems like this should be allowed though since I can easily transform the condition with deMorgan into something equivalent that the analyzer doesn't complain on. The transformed condition is just harder to read/comprehend.
The text was updated successfully, but these errors were encountered: