@@ -14,6 +14,9 @@ void main() {
1414
1515@reflectiveTest
1616class UnawaitedFuturesTest extends LintRuleTest {
17+ @override
18+ bool get addMetaPackageDep => true ;
19+
1720 @override
1821 String get lintRule => LintNames .unawaited_futures;
1922
@@ -31,6 +34,19 @@ class C {
3134 );
3235 }
3336
37+ test_binaryExpression_unawaited_awaitNotRequired () async {
38+ await assertNoDiagnostics (r'''
39+ import 'package:meta/meta.dart';
40+ void f(C a, C b) async {
41+ a + b;
42+ }
43+ class C {
44+ @awaitNotRequired
45+ Future<int> operator +(C other) async => 7;
46+ }
47+ ''' );
48+ }
49+
3450 test_boundToFuture_unawaited () async {
3551 // This behavior was not necessarily designed, but this test documents the
3652 // current behavior.
@@ -96,6 +112,17 @@ Future<int> g() => Future.value(0);
96112 );
97113 }
98114
115+ test_functionCall_interpolated_unawaited_awaitNotRequired () async {
116+ await assertNoDiagnostics (r'''
117+ import 'package:meta/meta.dart';
118+ void f() async {
119+ '${g()}';
120+ }
121+ @awaitNotRequired
122+ Future<int> g() => Future.value(0);
123+ ''' );
124+ }
125+
99126 test_functionCall_nullableFuture_unawaited () async {
100127 await assertDiagnostics (
101128 r'''
@@ -129,19 +156,18 @@ Future<int> g() => Future.value(0);
129156 );
130157 }
131158
132- test_functionCallInCascade_assignment () async {
159+ test_functionCall_unawaited_awaitNotRequired () async {
133160 await assertNoDiagnostics (r'''
161+ import 'package:meta/meta.dart';
134162void f() async {
135- C()..futureField = g();
163+ g();
136164}
165+ @awaitNotRequired
137166Future<int> g() => Future.value(0);
138- class C {
139- Future<int>? futureField;
140- }
141167''' );
142168 }
143169
144- test_functionCallInCascade_inAsync () async {
170+ test_functionCallInCascade () async {
145171 await assertDiagnostics (
146172 r'''
147173void f() async {
@@ -155,6 +181,33 @@ class C {
155181 );
156182 }
157183
184+ // TODO(srawlins): Test that `@awaitNotRequired` is inherited.
185+
186+ test_functionCallInCascade_assignment () async {
187+ await assertNoDiagnostics (r'''
188+ void f() async {
189+ C()..futureField = g();
190+ }
191+ Future<int> g() => Future.value(0);
192+ class C {
193+ Future<int>? futureField;
194+ }
195+ ''' );
196+ }
197+
198+ test_functionCallInCascade_awaitNotRequired () async {
199+ await assertNoDiagnostics (r'''
200+ import 'package:meta/meta.dart';
201+ void f() async {
202+ C()..doAsync();
203+ }
204+ class C {
205+ @awaitNotRequired
206+ Future<void> doAsync() async {}
207+ }
208+ ''' );
209+ }
210+
158211 test_functionCallInCascade_indexAssignment () async {
159212 await assertNoDiagnostics (r'''
160213void f() async {
@@ -180,6 +233,19 @@ class C {
180233 }
181234
182235 test_instanceProperty_unawaited () async {
236+ await assertNoDiagnostics (r'''
237+ import 'package:meta/meta.dart';
238+ void f(C c) async {
239+ c.p;
240+ }
241+ abstract class C {
242+ @awaitNotRequired
243+ Future<int> get p;
244+ }
245+ ''' );
246+ }
247+
248+ test_instanceProperty_unawaited_awaitNotRequired () async {
183249 await assertDiagnostics (
184250 r'''
185251void f(C c) async {
@@ -204,7 +270,7 @@ void f(Future<int> p) async {
204270 );
205271 }
206272
207- test_unaryExpression_unawaited () async {
273+ test_prefixExpression_unawaited () async {
208274 await assertDiagnostics (
209275 r'''
210276void f(C a) async {
@@ -218,6 +284,19 @@ class C {
218284 );
219285 }
220286
287+ test_prefixExpression_unawaited_awaitNotRequired () async {
288+ await assertNoDiagnostics (r'''
289+ import 'package:meta/meta.dart';
290+ void f(C a) async {
291+ -a;
292+ }
293+ class C {
294+ @awaitNotRequired
295+ Future<int> operator -() async => 7;
296+ }
297+ ''' );
298+ }
299+
221300 test_undefinedIdentifier () async {
222301 await assertDiagnostics (
223302 r'''
0 commit comments