Skip to content

Commit c1cacbe

Browse files
pqCommit Queue
authored and
Commit Queue
committed
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 <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 4e7a6a0 commit c1cacbe

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

pkg/linter/lib/src/rules/await_only_futures.dart

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/visitor.dart';
7+
import 'package:analyzer/dart/element/element.dart';
78
import 'package:analyzer/dart/element/type.dart';
89

910
import '../analyzer.dart';
@@ -70,6 +71,7 @@ class _Visitor extends SimpleAstVisitor<void> {
7071

7172
var type = node.expression.staticType;
7273
if (!(type == null ||
74+
type.element is ExtensionTypeElement ||
7375
type.isDartAsyncFuture ||
7476
type is DynamicType ||
7577
type is InvalidType ||

pkg/linter/test/rules/await_only_futures_test.dart

+23
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ class AwaitOnlyFuturesTest extends LintRuleTest {
1717
@override
1818
String get lintRule => 'await_only_futures';
1919

20+
test_extensionType_implementingFuture() async {
21+
await assertNoDiagnostics(r'''
22+
extension type E(Future f) implements Future { }
23+
24+
void f() async {
25+
await E(Future.value());
26+
}
27+
''');
28+
}
29+
30+
test_extensionType_notImplementingFuture() async {
31+
await assertDiagnostics(r'''
32+
extension type E(int c) { }
33+
34+
void f() async {
35+
await E(1);
36+
}
37+
''', [
38+
// No lint
39+
error(CompileTimeErrorCode.AWAIT_OF_EXTENSION_TYPE_NOT_FUTURE, 48, 5),
40+
]);
41+
}
42+
2043
test_undefinedClass() async {
2144
await assertDiagnostics(r'''
2245
Undefined f() async => await f();

0 commit comments

Comments
 (0)