mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
[dart2wasm] Fix exception handling in async functions
Fixes #55347. Change-Id: I9ced2a4c06e6cb9714dc47e3661f5582c70cdeb0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361063 Reviewed-by: Erik Ernst <eernst@google.com> Reviewed-by: Jackson Gardner <jacksongardner@google.com> Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
parent
4fd5d783c1
commit
6de879e0f5
|
@ -1123,8 +1123,11 @@ class AsyncCodeGenerator extends CodeGenerator {
|
|||
|
||||
for (int catchIdx = 0; catchIdx < node.catches.length; catchIdx += 1) {
|
||||
final Catch catch_ = node.catches[catchIdx];
|
||||
final Catch? nextCatch =
|
||||
node.catches.length < catchIdx ? node.catches[catchIdx + 1] : null;
|
||||
|
||||
final nextCatchIdx = catchIdx + 1;
|
||||
final Catch? nextCatch = nextCatchIdx < node.catches.length
|
||||
? node.catches[nextCatchIdx]
|
||||
: null;
|
||||
|
||||
_emitTargetLabel(innerTargets[catch_]!);
|
||||
|
||||
|
|
52
tests/language/exception/try_multiple_catch_async.dart
Normal file
52
tests/language/exception/try_multiple_catch_async.dart
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Tests try-catch in `async`, with multiple `catch`/`on` blocks, where the
|
||||
// first type test in the `catch`/`on` blocks fail and the subsequent test
|
||||
// passes.
|
||||
//
|
||||
// This is a regression test for issue #55347.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class MyException implements Exception {
|
||||
MyException([this.message]);
|
||||
|
||||
final String? message;
|
||||
|
||||
@override
|
||||
String toString() => 'MyException($message)';
|
||||
}
|
||||
|
||||
class MyOtherException implements Exception {
|
||||
MyOtherException([this.message]);
|
||||
|
||||
final String? message;
|
||||
|
||||
@override
|
||||
String toString() => 'MyOtherException($message)';
|
||||
}
|
||||
|
||||
Future<String> asynchronouslyThrowException() async {
|
||||
throw MyException('Throwing an error!');
|
||||
}
|
||||
|
||||
Future<String?> test() async {
|
||||
try {
|
||||
await asynchronouslyThrowException();
|
||||
Expect.fail('Exception is not thrown');
|
||||
} on MyOtherException {
|
||||
Expect.fail('Wrong exception caught');
|
||||
} on MyException {
|
||||
return 'Success';
|
||||
} catch (error) {
|
||||
Expect.fail('Wrong exception caught');
|
||||
}
|
||||
Expect.fail('No exception caught');
|
||||
return null;
|
||||
}
|
||||
|
||||
void main() async {
|
||||
Expect.equals(await test(), 'Success');
|
||||
}
|
Loading…
Reference in a new issue