Closed
Description
As reported in:
- Analyzer incorrectly reports "In constant expressions, operands of this operator must be of type 'bool', 'num', 'String' or 'null'" for == operator with enum operand sdk#26980
- const_eval_throws_exception error sdk#36511
- CFE produces the following error in flutter code when constant_update_2018 flag is turned on sdk#36564
- VM fails to report an error when equality comparing enums in a const context sdk#36528
The specification does not allow ==
to be used on enum values in const contexts. This seems reasonable to allow, customers have asked for it, and it should be an easy change to make.
Example from dart-lang/sdk#26980
enum MyEnum { a, b }
class Test {
const Test(MyEnum arg) : value = arg == MyEnum.a ? 0 : 1;
final int value;
}
void main() {
Test q = const Test(MyEnum.a);
Test r = const Test(MyEnum.a);
print(identical(q, r));
}