aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-08-02 16:32:24 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-08-02 16:32:24 -0400
commit5bd330e76c4b9bfc341dcba1732a8ac9277e133d (patch)
treea2b86dd5ec3cbc68b0ea66ac96a75cce06701318 /test
parentb3b6a98451a9703dc15a1ee5f48acde23de3c491 (diff)
downloadzig-5bd330e76c4b9bfc341dcba1732a8ac9277e133d.tar.gz
zig-5bd330e76c4b9bfc341dcba1732a8ac9277e133d.zip
add heap allocated async function frame test
Diffstat (limited to 'test')
-rw-r--r--test/stage1/behavior/coroutines.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/stage1/behavior/coroutines.zig b/test/stage1/behavior/coroutines.zig
index 28dd834bfe..b22f50c228 100644
--- a/test/stage1/behavior/coroutines.zig
+++ b/test/stage1/behavior/coroutines.zig
@@ -333,3 +333,27 @@ async fn testBreakFromSuspend(my_result: *i32) void {
suspend;
my_result.* += 1;
}
+
+test "heap allocated async function frame" {
+ const S = struct {
+ var x: i32 = 42;
+
+ fn doTheTest() !void {
+ const frame = try std.heap.direct_allocator.create(@Frame(someFunc));
+ defer std.heap.direct_allocator.destroy(frame);
+
+ expect(x == 42);
+ frame.* = async someFunc();
+ expect(x == 43);
+ resume frame;
+ expect(x == 44);
+ }
+
+ fn someFunc() void {
+ x += 1;
+ suspend;
+ x += 1;
+ }
+ };
+ try S.doTheTest();
+}