Skip to content

Enhanced enums: dart throws unexpected compile error for the declaration of enum with factory. #48181

Closed
@iarkh

Description

@iarkh

Dart SDK version: 2.17.0-28.0.dev (dev) (Tue Jan 18 12:05:00 2022 -0800) on "windows_x64"

Dart produces a compile time error for the following source code example:

// SharedOptions=--enable-experiment=enhanced-enums
enum E {
  e1,
  e2;
  factory E.f(int i) => E.values[i];
}

main() {}

Seems like there should not be an error here.

Sample output is:

$> dart --enable-experiment=enhanced-enums test.dart
test.dart:2:6: Error: Constant evaluation error:
enum E {
     ^
test.dart:2:6: Context: Expected constant 'null' to be of type 'E', but was of type 'Null'.
 - 'E' is from 'test.dart'.
enum E {
     ^
test.dart:2:6: Context: While analyzing:
enum E {
     ^

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions