summaryrefslogtreecommitdiff
path: root/tests/asynchronous
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-01-23 22:39:42 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2019-01-24 09:15:25 +0100
commit2e5682fd195f5109862eabc18144032175799104 (patch)
treeb4e9e0739eacdb410731d3013129076154f4cd27 /tests/asynchronous
parenta617f41413dec4da1891bfd5a1d4553465370017 (diff)
downloadvala-2e5682fd195f5109862eabc18144032175799104.tar.gz
codegen: Properly handle and catch inner-error of finally-block
If all inner-errors are caught there is no jump-out of the current finally- block therefore the control-flow analyzer is happy. To make this work the surrounding inner-error must not be used or changed here. Fixes https://gitlab.gnome.org/GNOME/vala/issues/742
Diffstat (limited to 'tests/asynchronous')
-rw-r--r--tests/asynchronous/catch-in-finally.vala72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/asynchronous/catch-in-finally.vala b/tests/asynchronous/catch-in-finally.vala
new file mode 100644
index 000000000..9f0f95226
--- /dev/null
+++ b/tests/asynchronous/catch-in-finally.vala
@@ -0,0 +1,72 @@
+errordomain FooError {
+ FAIL
+}
+
+async void fail () throws FooError {
+ throw new FooError.FAIL ("fail");
+}
+
+async void may_fail () throws FooError {
+}
+
+async void foo () throws FooError {
+ try {
+ yield fail ();
+ } finally {
+ try {
+ yield may_fail ();
+ } catch (FooError e) {
+ assert_not_reached ();
+ }
+ }
+ assert_not_reached ();
+}
+
+async void bar () throws FooError {
+ try {
+ yield may_fail ();
+ } finally {
+ try {
+ yield fail ();
+ } catch (FooError e) {
+ }
+ }
+
+ try {
+ yield fail ();
+ } finally {
+ try {
+ yield may_fail ();
+ } catch (FooError e) {
+ assert_not_reached ();
+ }
+ }
+ assert_not_reached ();
+}
+
+async void run () {
+ foo.begin ((o,r) => {
+ try {
+ foo.end (r);
+ } catch (FooError e) {
+ assert (e.message == "fail");
+ }
+ });
+
+ bar.begin ((o,r) => {
+ try {
+ bar.end (r);
+ } catch (FooError e) {
+ assert (e.message == "fail");
+ loop.quit ();
+ }
+ });
+}
+
+MainLoop loop;
+
+void main () {
+ loop = new MainLoop ();
+ run.begin ();
+ loop.run ();
+}