extension_type_implements_representation_not_supertype
'{0}'('{1}' 的表示类型)不是 '{2}'('{3}' 的表示类型)的超类型。
描述
#当一个扩展类型实现另一个扩展类型,并且被实现的扩展类型的表示类型不是实现该扩展类型的表示类型的子类型时,分析器会产生此诊断信息。
示例
#以下代码会产生此诊断信息,因为扩展类型 B
实现了 A
,但 A
的表示类型 (num
) 不是 B
的表示类型 (String
) 的子类型。
dart
extension type A(num i) {}
extension type B(String s) implements A {}
常见修复方法
#要么更改两个扩展类型的表示类型,使得被实现类型的表示类型是实现该类型的表示类型的超类型
dart
extension type A(num i) {}
extension type B(int n) implements A {}
或者从 implements 子句中移除被实现的类型
dart
extension type A(num i) {}
extension type B(String s) {}