Skip to content

[Enhanced enums] No error in CFE when Enum subtype overrides index #48353

Closed
@sgrekhov

Description

@sgrekhov

The following co19 test fails in CFE now

abstract class E1 extends Enum {
  int get index => 42; // No expected error here in CFE
//        ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

abstract class E2 extends Enum {
  List<E2> get index => [];
//             ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
  print(E1);
  print(E2);
}

According to the specification

It's a compile-time error if a class, mixin or enum declaration has Enum as a superinterface, and it declares a non-abstract instance member named index. That member would override the index getter inherited from Enum, and we currently do not allow that.

So there should be an error.

Tested on Dart SDK version: 2.17.0-edge.21a5f734562eb0d2fca0f9b5b646632fbcdb04cb (be) (Wed Feb 9 02:28:41 2022 +0000) on "linux_x64"

UPD There is no expected error in CFE on the enum as well

enum E1 {
  e1,
  e2;

  final int index = 42; // No expected error on CFE
//          ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions