Skip to content

Analyzer incorrectly reports "In constant expressions, operands of this operator must be of type 'bool', 'num', 'String' or 'null'" for == operator with enum operand #26980

Closed
@Hixie

Description

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

VM prints "true", showing that the const expression is fine.

Analyzer says:

[error] In constant expressions, operands of this operator must be of type 'bool', 'num', 'String' or 'null' (test.dart, line 4, col 36)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions