跳到主要內容

optional_parameter_in_operator

在定義運算子時,不允許使用可選引數。

描述

#

當運算子宣告中的一個或多個引數是可選引數時,分析器會產生此診斷。

示例

#

以下程式碼會產生此診斷,因為引數 other 是一個可選引數

dart
class C {
  C operator +([C? other]) => this;
}

常見修復方法

#

使所有引數都成為必需引數

dart
class C {
  C operator +(C other) => this;
}