Skip to content

Allow == on Enum values in const expressions. #312

Closed
@leafpetersen

Description

@leafpetersen

As reported in:

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));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    state-duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions