diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-09-07 00:12:15 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-09-07 00:13:12 -0400 |
| commit | d1a98ccff481183d7fc53e45a902ef273c3d6aeb (patch) | |
| tree | b03efbb135bae39fcf6968b505ad67e4c6a33bda /test | |
| parent | 9ca8d9e21ad657b023c23db5c440fb79a3303771 (diff) | |
| download | zig-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.zig | 28 |
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(); +} |
