aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-09-07 00:12:15 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-09-07 00:13:12 -0400
commitd1a98ccff481183d7fc53e45a902ef273c3d6aeb (patch)
treeb03efbb135bae39fcf6968b505ad67e4c6a33bda /test
parent9ca8d9e21ad657b023c23db5c440fb79a3303771 (diff)
downloadzig-d1a98ccff481183d7fc53e45a902ef273c3d6aeb.tar.gz
zig-d1a98ccff481183d7fc53e45a902ef273c3d6aeb.zip
implement spills when expressions used across suspend points
closes #3077
Diffstat (limited to 'test')
-rw-r--r--test/stage1/behavior/async_fn.zig28
1 files changed, 20 insertions, 8 deletions
diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig
index 3079a7b98a..cef950fe0c 100644
--- a/test/stage1/behavior/async_fn.zig
+++ b/test/stage1/behavior/async_fn.zig
@@ -921,12 +921,10 @@ fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type {
var sum: u32 = 0;
f1_awaited = true;
- const result_f1 = await f1; // TODO https://github.com/ziglang/zig/issues/3077
- sum += try result_f1;
+ sum += try await f1;
f2_awaited = true;
- const result_f2 = await f2; // TODO https://github.com/ziglang/zig/issues/3077
- sum += try result_f2;
+ sum += try await f2;
return sum;
}
@@ -943,8 +941,7 @@ fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type {
fn amain(result: *u32) void {
var x = async fib(std.heap.direct_allocator, 10);
- const res = await x; // TODO https://github.com/ziglang/zig/issues/3077
- result.* = res catch unreachable;
+ result.* = (await x) catch unreachable;
}
};
}
@@ -1002,8 +999,7 @@ test "@asyncCall using the result location inside the frame" {
return 1234;
}
fn getAnswer(f: anyframe->i32, out: *i32) void {
- var res = await f; // TODO https://github.com/ziglang/zig/issues/3077
- out.* = res;
+ out.* = await f;
}
};
var data: i32 = 1;
@@ -1124,3 +1120,19 @@ test "await used in expression and awaiting fn with no suspend but async calling
};
_ = async S.atest();
}
+
+test "await used in expression after a fn call" {
+ const S = struct {
+ fn atest() void {
+ var f1 = async add(3, 4);
+ var sum: i32 = 0;
+ sum = foo() + await f1;
+ expect(sum == 8);
+ }
+ async fn add(a: i32, b: i32) i32 {
+ return a + b;
+ }
+ fn foo() i32 { return 1; }
+ };
+ _ = async S.atest();
+}