メインコンテンツにスキップ

await_of_incompatible_type

'await' 式は、'Future' のサブタイプではない拡張型を持つ式には使用できません。

説明

#

この診断は、await 式内の式の型が拡張型であり、その拡張型が Future のサブクラスではない場合に、アナライザーによって生成されます。

#

以下のコードは、拡張型 EFuture のサブクラスではないため、この診断を生成します。

dart
extension type E(int i) {}

void f(E e) async {
  await e;
}

一般的な修正

#

拡張型が正しく定義されている場合は、await を削除してください。

dart
extension type E(int i) {}

void f(E e) {
  e;
}

拡張型が await 可能であることを意図している場合は、implements 句に Future (または Future のサブタイプ) を追加し (まだ implements 句がない場合は追加)、表現型を一致させてください。

dart
extension type E(Future<int> i) implements Future<int> {}

void f(E e) async {
  await e;
}