跳到主要內容

invalid_extension_argument_count

擴充套件覆蓋必須且只能有一個引數:擴充套件方法中 'this' 的值。

描述

#

當擴充套件覆蓋沒有且只有一個引數時,分析器會生成此診斷。該引數是用於計算擴充套件方法內 this 值的表示式,因此必須有一個引數。

示例

#

以下程式碼生成此診斷,因為它沒有引數

dart
extension E on String {
  String join(String other) => '$this $other';
}

void f() {
  E().join('b');
}

此外,以下程式碼生成此診斷,因為它有一個以上引數

dart
extension E on String {
  String join(String other) => '$this $other';
}

void f() {
  E('a', 'b').join('c');
}

常見修復方法

#

為擴充套件覆蓋提供一個引數

dart
extension E on String {
  String join(String other) => '$this $other';
}

void f() {
  E('a').join('b');
}