super_formal_parameter_type_is_not_subtype_of_associated
The type '{0}' of this parameter isn't a subtype of the type '{1}' of the associated super constructor parameter.
Description
#The analyzer produces this diagnostic when the type of a super parameter isn't a subtype of the corresponding parameter from the super constructor.
Example
#The following code produces this diagnostic because the type of the super
parameter x
in the constructor for B
isn't a subtype of the parameter
x
in the constructor for A
:
class A {
A(num x);
}
class B extends A {
B(String super.x);
}
Common fixes
#If the type of the super parameter can be the same as the parameter from the super constructor, then remove the type annotation from the super parameter (if the type is implicit, it is inferred from the type in the super constructor):
class A {
A(num x);
}
class B extends A {
B(super.x);
}
If the type of the super parameter can be a subtype of the corresponding parameter's type, then change the type of the super parameter:
class A {
A(num x);
}
class B extends A {
B(int super.x);
}
If the type of the super parameter can't be changed, then use a normal parameter instead of a super parameter:
class A {
A(num x);
}
class B extends A {
B(String x) : super(x.length);
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。