await_of_incompatible_type
The 'await' expression can't be used for an expression with an extension type that is not a subtype of 'Future'.
Description
#The analyzer produces this diagnostic when the type of the expression in
an await
expression is an extension type, and the extension type isn't a
subclass of Future
.
Example
#The following code produces this diagnostic because the extension type E
isn't a subclass of Future
:
extension type E(int i) {}
void f(E e) async {
await e;
}
Common fixes
#If the extension type is correctly defined, then remove the await
:
extension type E(int i) {}
void f(E e) {
e;
}
If the extension type is intended to be awaitable, then add Future
(or a
subtype of Future
) to the implements
clause (adding an implements
clause if there isn't one already), and make the representation type
match:
extension type E(Future<int> i) implements Future<int> {}
void f(E e) async {
await e;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。