aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-02-05 18:58:58 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-02-05 18:58:58 -0500
commit7749ffd797e927f93051060db49b76c595879697 (patch)
tree53f3861a67d42e47ea35636f81a6a43618e44483 /test
parentb9c943b0667ed8253382cb787d4705f6619f7296 (diff)
downloadzig-7749ffd797e927f93051060db49b76c595879697.tar.gz
zig-7749ffd797e927f93051060db49b76c595879697.zip
try expression can omit variable assignments
Diffstat (limited to 'test')
-rw-r--r--test/cases/try.zig26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/cases/try.zig b/test/cases/try.zig
index 17b78b2115..cf1bf49157 100644
--- a/test/cases/try.zig
+++ b/test/cases/try.zig
@@ -31,3 +31,29 @@ error CrappedOut;
fn returnsTen() -> %i32 {
10
}
+
+fn tryWithoutVars() {
+ @setFnTest(this);
+
+ const result1 = try (failIfTrue(true)) {
+ 1
+ } else {
+ i32(2)
+ };
+ assert(result1 == 2);
+
+ const result2 = try (failIfTrue(false)) {
+ 1
+ } else {
+ i32(2)
+ };
+ assert(result2 == 1);
+}
+
+fn failIfTrue(ok: bool) -> %void {
+ if (ok) {
+ return error.ItBroke;
+ } else {
+ return;
+ }
+}