sdk icon indicating copy to clipboard operation
sdk copied to clipboard

[dart2wasm] Execute `finally` blocks crossed by `break` or `continue`

Open askeksa-google opened this issue 3 years ago • 1 comments

When a try block with a finally block is exited via a break or continue statement, the code in the finally block runs. This mechanism is currently not implemented in dart2wasm.

This causes the following co19 tests to hang due to an await for loop not cancelling the stream subscription on exit:

Language/Statements/Continue/async_loops_t07
Language/Statements/Continue/async_loops_t08
LibTest/async/Stream/Stream.fromFutures_all_t01
LibTest/async/Stream/Stream.fromIterable_all_t01
LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t01
LibTest/async/StreamController/stream_all_A01_t01

askeksa-google avatar Sep 21 '22 10:09 askeksa-google

Repro:

void main() {
  bool yes = false;
  while (true) {
    try {
      break;
    } finally {
      yes = true;
    }
  }
  print(yes);
}

Prints 'true' when run with AOT/JIT, prints 'false' with dart2wasm.

Slightly more complicated example that tests changing control flow in finally:

void main() {
  for (var i = 0; i < 5; i += 1) {
    try {
      try {
        try {
          break;
        } catch (_) {
          print("A");
        }
      } finally {
        throw "foo";
      }
    } catch (_) {
      print("B");
    }
  }
}

osa1 avatar Sep 21 '22 12:09 osa1

https://dart-review.googlesource.com/c/sdk/+/262240

osa1 avatar Oct 03 '22 09:10 osa1