Skip to content

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

Closed

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.)

Activity

  1. added
    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
    on Apr 8, 2019
  2. a-siva commented on Apr 11, 2019

    @a-siva
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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