Skip to content

VM fails to report an error when equality comparing enums in a const context #36528

@stereotype441

Description

@stereotype441

Consider the following code, adapted from the repro for #36511:

enum Foo {
  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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.legacy-area-front-endLegacy: Use area-dart-model instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions