2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
+ import 'package:analyzer/dart/analysis/features.dart' ;
5
6
import 'package:analyzer/src/error/codes.g.dart' ;
6
7
import 'package:test_reflective_loader/test_reflective_loader.dart' ;
7
8
@@ -10,6 +11,7 @@ import '../dart/resolution/context_collection_resolution.dart';
10
11
main () {
11
12
defineReflectiveSuite (() {
12
13
defineReflectiveTests (UnusedCatchClauseTest );
14
+ defineReflectiveTests (UnusedCatchClauseTestWildCardVariablesTest );
13
15
});
14
16
}
15
17
@@ -27,6 +29,16 @@ main() {
27
29
]);
28
30
}
29
31
32
+ test_on_unusedStack_wildcard () async {
33
+ await assertNoErrorsInCode (r'''
34
+ main() {
35
+ try {
36
+ } on String catch (exception, _) {
37
+ }
38
+ }
39
+ ''' );
40
+ }
41
+
30
42
test_on_usedException () async {
31
43
await assertNoErrorsInCode (r'''
32
44
main() {
@@ -48,6 +60,26 @@ main() {
48
60
''' );
49
61
}
50
62
63
+ test_unusedException_underscores () async {
64
+ await assertNoErrorsInCode (r'''
65
+ main() {
66
+ try {
67
+ } catch (__) {
68
+ }
69
+ }
70
+ ''' );
71
+ }
72
+
73
+ test_unusedException_wildcard () async {
74
+ await assertNoErrorsInCode (r'''
75
+ main() {
76
+ try {
77
+ } catch (_) {
78
+ }
79
+ }
80
+ ''' );
81
+ }
82
+
51
83
test_usedException () async {
52
84
await assertNoErrorsInCode (r'''
53
85
main() {
@@ -59,3 +91,24 @@ main() {
59
91
''' );
60
92
}
61
93
}
94
+
95
+ @reflectiveTest
96
+ class UnusedCatchClauseTestWildCardVariablesTest extends UnusedCatchClauseTest {
97
+ @override
98
+ List <String > get experiments => [
99
+ ...super .experiments,
100
+ Feature .wildcard_variables.enableString,
101
+ ];
102
+
103
+ test_on_unusedStack_underscores () async {
104
+ await assertErrorsInCode (r'''
105
+ main() {
106
+ try {
107
+ } on String catch (exception, __) {
108
+ }
109
+ }
110
+ ''' , [
111
+ error (WarningCode .UNUSED_CATCH_STACK , 49 , 2 ),
112
+ ]);
113
+ }
114
+ }
0 commit comments