跳至主要內容

test_types_in_equals

在 '==' 中缺少 '{0}' 的型別測試。

描述

#

== 運算子的過載沒有包含對引數值的型別測試時,分析器會生成此診斷。

示例

#

以下程式碼會生成此診斷,因為 other 未進行型別測試

dart
class C {
  final int f;

  C(this.f);

  @override
  bool operator ==(Object other) {
    return (other as C).f == f;
  }
}

常見修復

#

在計算返回值時進行 is 測試

dart
class C {
  final int f;

  C(this.f);

  @override
  bool operator ==(Object other) {
    return other is C && other.f == f;
  }
}