illegal_concrete_enum_member
A concrete instance member named '{0}' can't be declared in a class that implements 'Enum'.
A concrete instance member named '{0}' can't be inherited from '{1}' in a class that implements 'Enum'.
Description
#The analyzer produces this diagnostic when either an enum declaration, a
class that implements Enum
, or a mixin with a superclass constraint of
Enum
, declares or inherits a concrete instance member named either
index
, hashCode
, or ==
.
Examples
#The following code produces this diagnostic because the enum E
declares
an instance getter named index
:
enum E {
v;
int get index => 0;
}
The following code produces this diagnostic because the class C
, which
implements Enum
, declares an instance field named hashCode
:
abstract class C implements Enum {
int hashCode = 0;
}
The following code produces this diagnostic because the class C
, which
indirectly implements Enum
through the class A
, declares an instance
getter named hashCode
:
abstract class A implements Enum {}
abstract class C implements A {
int get hashCode => 0;
}
The following code produces this diagnostic because the mixin M
, which
has Enum
in the on
clause, declares an explicit operator named ==
:
mixin M on Enum {
bool operator ==(Object other) => false;
}
Common fixes
#Rename the conflicting member:
enum E {
v;
int get getIndex => 0;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。