44
44
''' );
45
45
}
46
46
47
+ test_destructured_listPattern_wildcard () async {
48
+ await assertDiagnostics (r'''
49
+ f() {
50
+ var [_, b] = ['a', 'b'];
51
+ }
52
+ ''' , [
53
+ lint (8 , 3 ),
54
+ ]);
55
+ }
56
+
57
+ test_destructured_listPattern_wildcard_parenthesized () async {
58
+ await assertDiagnostics (r'''
59
+ f() {
60
+ var [(_), b] = ['a', 'b'];
61
+ }
62
+ ''' , [
63
+ lint (8 , 3 ),
64
+ ]);
65
+ }
66
+
67
+ test_destructured_listPattern_wildcard_single () async {
68
+ await assertNoDiagnostics (r'''
69
+ f() {
70
+ var [_] = ['a'];
71
+ }
72
+ ''' );
73
+ }
74
+
75
+ test_destructured_listPattern_wildcard_single_parenthesized () async {
76
+ await assertNoDiagnostics (r'''
77
+ f() {
78
+ var [(_)] = ['a'];
79
+ }
80
+ ''' );
81
+ }
82
+
47
83
test_destructured_listPatternWithRest () async {
48
84
await assertDiagnostics (r'''
49
85
f() {
@@ -90,6 +126,24 @@ f() {
90
126
''' );
91
127
}
92
128
129
+ test_destructured_mapPattern_wildcard () async {
130
+ await assertDiagnostics (r'''
131
+ f() {
132
+ var {'first': a, 'second': _} = {'first': 1, 'second': 2};
133
+ }
134
+ ''' , [
135
+ lint (8 , 3 ),
136
+ ]);
137
+ }
138
+
139
+ test_destructured_mapPattern_wildcard_single () async {
140
+ await assertNoDiagnostics (r'''
141
+ f() {
142
+ var {'first': _} = {'first': 1};
143
+ }
144
+ ''' );
145
+ }
146
+
93
147
test_destructured_objectPattern () async {
94
148
await assertDiagnostics (r'''
95
149
class A {
@@ -129,6 +183,40 @@ f() {
129
183
''' );
130
184
}
131
185
186
+ test_destructured_objectPattern_wildcard () async {
187
+ await assertNoDiagnostics (r'''
188
+ class A {
189
+ int a;
190
+ A(this.a);
191
+ }
192
+ f() {
193
+ var A(a: _) = A(1);
194
+ }
195
+ ''' );
196
+ }
197
+
198
+ test_destructured_objectPattern_wildcard_multipleFields () async {
199
+ await assertDiagnostics (r'''
200
+ class A {
201
+ int a, b;
202
+ A(this.a, this.b);
203
+ }
204
+ f() {
205
+ var A(a: x, b: _) = A(1, 2);
206
+ }
207
+ ''' , [
208
+ lint (53 , 3 ),
209
+ ]);
210
+ }
211
+
212
+ test_destructured_parenthesizedPattern_wildcard () async {
213
+ await assertNoDiagnostics (r'''
214
+ f() {
215
+ var (_) = ('a');
216
+ }
217
+ ''' );
218
+ }
219
+
132
220
test_destructured_recordPattern () async {
133
221
await assertDiagnostics (r'''
134
222
f() {
@@ -178,6 +266,16 @@ f() {
178
266
''' );
179
267
}
180
268
269
+ test_destructured_recordPattern_forLoop_wildcard () async {
270
+ await assertDiagnostics (r'''
271
+ f() {
272
+ for (var (_, b) in [(1, 2)]) { }
273
+ }
274
+ ''' , [
275
+ lint (21 , 1 ),
276
+ ]);
277
+ }
278
+
181
279
test_destructured_recordPattern_mutated () async {
182
280
await assertNoDiagnostics (r'''
183
281
f() {
@@ -187,6 +285,24 @@ f() {
187
285
''' );
188
286
}
189
287
288
+ test_destructured_recordPattern_wildcard () async {
289
+ await assertDiagnostics (r'''
290
+ f() {
291
+ var (_, b) = ('a', 'b');
292
+ }
293
+ ''' , [
294
+ lint (8 , 3 ),
295
+ ]);
296
+ }
297
+
298
+ test_destructured_recordPattern_wildcard_multipleWildcards () async {
299
+ await assertNoDiagnostics (r'''
300
+ f() {
301
+ var (_, _) = ('a', 'b');
302
+ }
303
+ ''' );
304
+ }
305
+
190
306
test_destructured_recordPattern_withParenthesizedPattern () async {
191
307
await assertDiagnostics (r'''
192
308
f() {
@@ -223,6 +339,16 @@ f(Object o) {
223
339
''' );
224
340
}
225
341
342
+ test_ifPatternList_wildcard () async {
343
+ await assertDiagnostics (r'''
344
+ f(Object o) {
345
+ if (o case [int x, int _]) x;
346
+ }
347
+ ''' , [
348
+ lint (28 , 5 ),
349
+ ]);
350
+ }
351
+
226
352
test_ifPatternMap () async {
227
353
await assertDiagnostics (r'''
228
354
f(Object o) {
@@ -241,6 +367,14 @@ f(Object o) {
241
367
''' );
242
368
}
243
369
370
+ test_ifPatternMap_wildcard () async {
371
+ await assertNoDiagnostics (r'''
372
+ f(Object o) {
373
+ if (o case {'x': var _});
374
+ }
375
+ ''' );
376
+ }
377
+
244
378
test_ifPatternObject () async {
245
379
await assertDiagnostics (r'''
246
380
class C {
@@ -269,6 +403,19 @@ f(Object o) {
269
403
''' );
270
404
}
271
405
406
+ test_ifPatternObject_wildcard () async {
407
+ await assertNoDiagnostics (r'''
408
+ class C {
409
+ int c;
410
+ C(this.c);
411
+ }
412
+
413
+ f(Object o) {
414
+ if (o case C(c: var _));
415
+ }
416
+ ''' );
417
+ }
418
+
272
419
test_ifPatternRecord () async {
273
420
await assertDiagnostics (r'''
274
421
f(Object o) {
@@ -288,6 +435,16 @@ f(Object o) {
288
435
''' );
289
436
}
290
437
438
+ test_ifPatternRecord_wildcard () async {
439
+ await assertDiagnostics (r'''
440
+ f(Object o) {
441
+ if (o case (int x, int _)) x;
442
+ }
443
+ ''' , [
444
+ lint (28 , 5 ),
445
+ ]);
446
+ }
447
+
291
448
test_nonDeclaration_destructured_recordPattern () async {
292
449
await assertNoDiagnostics (r'''
293
450
f(String a, String b) {
@@ -340,6 +497,14 @@ void f() {
340
497
]);
341
498
}
342
499
500
+ test_notReassigned_withVar_wildcard () async {
501
+ await assertNoDiagnostics (r'''
502
+ void f() {
503
+ var _ = '';
504
+ }
505
+ ''' );
506
+ }
507
+
343
508
test_reassigned () async {
344
509
await assertNoDiagnostics (r'''
345
510
void f() {
@@ -405,6 +570,24 @@ f() {
405
570
''' );
406
571
}
407
572
573
+ test_switch_objectPattern_wildcard () async {
574
+ await assertDiagnostics (r'''
575
+ class A {
576
+ int a;
577
+ A(this.a);
578
+ }
579
+
580
+ f() {
581
+ switch (A(1)) {
582
+ case A(a: >0 && var _): print('');
583
+ }
584
+ }
585
+ ''' , [
586
+ // No lint.
587
+ error (WarningCode .UNNECESSARY_WILDCARD_PATTERN , 83 , 1 ),
588
+ ]);
589
+ }
590
+
408
591
test_switch_recordPattern () async {
409
592
await assertDiagnostics (r'''
410
593
f() {
@@ -435,6 +618,26 @@ f() {
435
618
case (var a, final int b): ++a;
436
619
}
437
620
}
621
+ ''' );
622
+ }
623
+
624
+ test_switch_recordPattern_wildcard () async {
625
+ await assertDiagnostics (r'''
626
+ f() {
627
+ switch ((1, 2)) {
628
+ case (var a, int _): a;
629
+ }
630
+ }
631
+ ''' , [
632
+ lint (36 , 5 ),
633
+ ]);
634
+ }
635
+
636
+ test_wildcardLocal () async {
637
+ await assertNoDiagnostics (r'''
638
+ f() {
639
+ var _ = 0;
640
+ }
438
641
''' );
439
642
}
440
643
}
0 commit comments