extension type support for `await_only_futures`
Fixes: https://github.com/dart-lang/linter/issues/4685
Change-Id: I7cbc1a2a99384d7bc049e4e98ce3de53209398dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322566
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/linter/lib/src/rules/await_only_futures.dart b/pkg/linter/lib/src/rules/await_only_futures.dart
index c12f97a..934e78f 100644
--- a/pkg/linter/lib/src/rules/await_only_futures.dart
+++ b/pkg/linter/lib/src/rules/await_only_futures.dart
@@ -4,6 +4,7 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
+import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import '../analyzer.dart';
@@ -70,6 +71,7 @@
var type = node.expression.staticType;
if (!(type == null ||
+ type.element is ExtensionTypeElement ||
type.isDartAsyncFuture ||
type is DynamicType ||
type is InvalidType ||
diff --git a/pkg/linter/test/rules/await_only_futures_test.dart b/pkg/linter/test/rules/await_only_futures_test.dart
index 70224f7..eab0b8f 100644
--- a/pkg/linter/test/rules/await_only_futures_test.dart
+++ b/pkg/linter/test/rules/await_only_futures_test.dart
@@ -17,6 +17,29 @@
@override
String get lintRule => 'await_only_futures';
+ test_extensionType_implementingFuture() async {
+ await assertNoDiagnostics(r'''
+extension type E(Future f) implements Future { }
+
+void f() async {
+ await E(Future.value());
+}
+''');
+ }
+
+ test_extensionType_notImplementingFuture() async {
+ await assertDiagnostics(r'''
+extension type E(int c) { }
+
+void f() async {
+ await E(1);
+}
+''', [
+ // No lint
+ error(CompileTimeErrorCode.AWAIT_OF_EXTENSION_TYPE_NOT_FUTURE, 48, 5),
+ ]);
+ }
+
test_undefinedClass() async {
await assertDiagnostics(r'''
Undefined f() async => await f();