-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Description
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.
class Foo {
const Foo({ this.child, this.text }) : assert(child == null || text == null);
final Widget child;
final String text;
}
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.
Metadata
Metadata
Assignees
Labels
area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
bwilkerson commentedon Oct 18, 2017
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.
lrhn commentedon Oct 19, 2017
Seems like a bug/oversight in the specification. I'm sympathetic to fixing it.
There'll likely be a clean-up of the const/potentially const specification for Dart 2, to iron out a few other problematic cases, but I see no reason not to commit to this immediately.
a14n commentedon Oct 19, 2017
Dup of #30288 ?
Fix spec to allow `x == null` in const expression where `x` is not nu…
srawlins commentedon Jun 22, 2018
The example no longer reports an error:
Hixie commentedon Aug 17, 2018
If I try to revert our workaround for this and use
assert(child == null || text == null)
, I get:lrhn commentedon Aug 20, 2018
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.
yjbanov commentedon Dec 4, 2018
FWIW this issue affects Hummingbird. We have to comment out some asserts to make the code run in DDC.
srawlins commentedon Sep 12, 2019
I think analyzer 2.5.0, with the const-update-2018, produces the correct behavior. Using the example above:
The analyzer only reports an error on the last line:
yjbanov commentedon Sep 12, 2019
We merged into the main Flutter repo and that repo passes the analyzer, so I guess this is fixed.
4 remaining items