File tree Expand file tree Collapse file tree 2 files changed +57
-2
lines changed Expand file tree Collapse file tree 2 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -1123,8 +1123,11 @@ class AsyncCodeGenerator extends CodeGenerator {
1123
1123
1124
1124
for (int catchIdx = 0 ; catchIdx < node.catches.length; catchIdx += 1 ) {
1125
1125
final Catch catch_ = node.catches[catchIdx];
1126
- final Catch ? nextCatch =
1127
- node.catches.length < catchIdx ? node.catches[catchIdx + 1 ] : null ;
1126
+
1127
+ final nextCatchIdx = catchIdx + 1 ;
1128
+ final Catch ? nextCatch = nextCatchIdx < node.catches.length
1129
+ ? node.catches[nextCatchIdx]
1130
+ : null ;
1128
1131
1129
1132
_emitTargetLabel (innerTargets[catch_]! );
1130
1133
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2
+ // for details. All rights reserved. Use of this source code is governed by a
3
+ // BSD-style license that can be found in the LICENSE file.
4
+
5
+ // Tests try-catch in `async`, with multiple `catch`/`on` blocks, where the
6
+ // first type test in the `catch`/`on` blocks fail and the subsequent test
7
+ // passes.
8
+ //
9
+ // This is a regression test for issue #55347.
10
+
11
+ import 'package:expect/expect.dart' ;
12
+
13
+ class MyException implements Exception {
14
+ MyException ([this .message]);
15
+
16
+ final String ? message;
17
+
18
+ @override
19
+ String toString () => 'MyException($message )' ;
20
+ }
21
+
22
+ class MyOtherException implements Exception {
23
+ MyOtherException ([this .message]);
24
+
25
+ final String ? message;
26
+
27
+ @override
28
+ String toString () => 'MyOtherException($message )' ;
29
+ }
30
+
31
+ Future <String > asynchronouslyThrowException () async {
32
+ throw MyException ('Throwing an error!' );
33
+ }
34
+
35
+ Future <String ?> test () async {
36
+ try {
37
+ await asynchronouslyThrowException ();
38
+ Expect .fail ('Exception is not thrown' );
39
+ } on MyOtherException {
40
+ Expect .fail ('Wrong exception caught' );
41
+ } on MyException {
42
+ return 'Success' ;
43
+ } catch (error) {
44
+ Expect .fail ('Wrong exception caught' );
45
+ }
46
+ Expect .fail ('No exception caught' );
47
+ return null ;
48
+ }
49
+
50
+ void main () async {
51
+ Expect .equals (await test (), 'Success' );
52
+ }
You can’t perform that action at this time.
0 commit comments