@@ -49,6 +49,14 @@ class _Visitor extends SimpleAstVisitor<void> {
49
49
var expr = node.expression;
50
50
if (expr is AssignmentExpression ) return ;
51
51
52
+ if (_isEnclosedInAsyncFunctionBody (node)) {
53
+ return ;
54
+ }
55
+
56
+ if (expr case AwaitExpression (: var expression)) {
57
+ expr = expression;
58
+ }
59
+
52
60
var type = expr.staticType;
53
61
if (type == null ) {
54
62
return ;
@@ -60,11 +68,7 @@ class _Visitor extends SimpleAstVisitor<void> {
60
68
return ;
61
69
}
62
70
63
- if (_isNotEnclosedInAsyncFunctionBody (node)) {
64
- // Future expression statement that isn't awaited in synchronous
65
- // function: while this is legal, it's a very frequent sign of an error.
66
- _reportOnExpression (expr);
67
- }
71
+ _reportOnExpression (expr);
68
72
}
69
73
}
70
74
@@ -73,6 +77,11 @@ class _Visitor extends SimpleAstVisitor<void> {
73
77
_visit (node.expression);
74
78
}
75
79
80
+ bool _isEnclosedInAsyncFunctionBody (AstNode node) {
81
+ var enclosingFunctionBody = node.thisOrAncestorOfType <FunctionBody >();
82
+ return enclosingFunctionBody? .isAsynchronous ?? false ;
83
+ }
84
+
76
85
/// Detects `Future.delayed(duration, [computation])` creations with a
77
86
/// computation.
78
87
bool _isFutureDelayedInstanceCreationWithComputation (Expression expr) =>
@@ -90,12 +99,6 @@ class _Visitor extends SimpleAstVisitor<void> {
90
99
expr.methodName.name == 'putIfAbsent' &&
91
100
_isMapClass (expr.methodName.element? .enclosingElement2);
92
101
93
- bool _isNotEnclosedInAsyncFunctionBody (AstNode node) {
94
- var enclosingFunctionBody = node.thisOrAncestorOfType <FunctionBody >();
95
- var isAsyncBody = enclosingFunctionBody? .isAsynchronous ?? false ;
96
- return ! isAsyncBody;
97
- }
98
-
99
102
void _reportOnExpression (Expression expr) {
100
103
rule.reportLint (switch (expr) {
101
104
MethodInvocation (: var methodName) => methodName,
@@ -109,7 +112,7 @@ class _Visitor extends SimpleAstVisitor<void> {
109
112
110
113
void _visit (Expression expr) {
111
114
if ((expr.staticType.isFutureOrFutureOr) &&
112
- _isNotEnclosedInAsyncFunctionBody (expr) &&
115
+ ! _isEnclosedInAsyncFunctionBody (expr) &&
113
116
expr is ! AssignmentExpression ) {
114
117
_reportOnExpression (expr);
115
118
}
0 commit comments