You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
VM fails to report an error when equality comparing enums in a const context #36528
Consider the following code, adapted from the repro for #36511:
enumFoo {
bar,
baz
}
main() {
const x =Foo.bar ==Foo.baz;
print(x);
}
This code is erroneous, because Foo.bar == Foo.baz is not a valid constant expression. Equality checks in constant expressions may only be used to compare primitive types; they may not be used to compare user-provided types such as Foo.
The analyzer correctly detects the error, reporting:
error • In constant expressions, operands of this operator must be of type 'bool', 'num', 'String' or 'null' at .../test.dart:6:13 • const_eval_type_bool_num_string
But the VM executes the code without complaint.
(I'm classifying this bug as both area-vm and area-front-end because I'm not sure whether the VM has been transitioned over to using the front end's constant evaluator yet. Feel free to reassign as appropriate.)
A language issue has been opened for tracking the feature 'Allow '==' on Enum values', closing this and with the VM switching to having the CFE evaluate constant expressions this is reported as an error by the VM now.
Activity
a-siva commentedon Apr 11, 2019
A language issue has been opened for tracking the feature 'Allow '==' on Enum values', closing this and with the VM switching to having the CFE evaluate constant expressions this is reported as an error by the VM now.
Fix enum instances comparison to use `equality ==` since dart has the…
Replace more enum instances comparison to use `equality ==` instead o…
`[cupertino_ui]` replace identical checks with equality when dealing …
`[cupertino_ui]` replace identical checks with equality when dealing …
`[material_ui]` replace identical checks with equality when dealing w…
`[cupertino_ui]` replace identical checks with equality when dealing …
`[material_ui]` replace identical checks with equality when dealing w…
Update more enum instances comparison to use equality == since dart h…