Skip to content

Commit 3bdc1f9

Browse files
pqCommit Queue
authored and
Commit Queue
committed
[wildcards] UNUSED_CATCH_CLAUSE tests
Fixes: #55721 Change-Id: I5e675c61a7d1eb0f6192f98146fd2dbd5dd0e2e5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366407 Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Kallen Tu <[email protected]>
1 parent b6207eb commit 3bdc1f9

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

pkg/analyzer/test/src/diagnostics/unused_catch_clause_test.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:analyzer/dart/analysis/features.dart';
56
import 'package:analyzer/src/error/codes.g.dart';
67
import 'package:test_reflective_loader/test_reflective_loader.dart';
78

@@ -10,6 +11,7 @@ import '../dart/resolution/context_collection_resolution.dart';
1011
main() {
1112
defineReflectiveSuite(() {
1213
defineReflectiveTests(UnusedCatchClauseTest);
14+
defineReflectiveTests(UnusedCatchClauseTestWildCardVariablesTest);
1315
});
1416
}
1517

@@ -27,6 +29,16 @@ main() {
2729
]);
2830
}
2931

32+
test_on_unusedStack_wildcard() async {
33+
await assertNoErrorsInCode(r'''
34+
main() {
35+
try {
36+
} on String catch (exception, _) {
37+
}
38+
}
39+
''');
40+
}
41+
3042
test_on_usedException() async {
3143
await assertNoErrorsInCode(r'''
3244
main() {
@@ -48,6 +60,26 @@ main() {
4860
''');
4961
}
5062

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+
5183
test_usedException() async {
5284
await assertNoErrorsInCode(r'''
5385
main() {
@@ -59,3 +91,24 @@ main() {
5991
''');
6092
}
6193
}
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

Comments
 (0)