Commit cbca6586e7

Andrew Kelley <andrew@ziglang.org>
2019-08-16 19:56:26
add test for struct parameter to async function being copied
closes #1155
1 parent 5a2cbe2
Changed files (1)
test
stage1
behavior
test/stage1/behavior/async_fn.zig
@@ -774,3 +774,46 @@ test "return from suspend block" {
     };
     _ = async S.doTheTest();
 }
+
+test "struct parameter to async function is copied to the frame" {
+    const S = struct {
+        const Point = struct {
+            x: i32,
+            y: i32,
+        };
+
+        var frame: anyframe = undefined;
+
+        fn doTheTest() void {
+            _ = async atest();
+            resume frame;
+        }
+
+        fn atest() void {
+            var f: @Frame(foo) = undefined;
+            bar(&f);
+            clobberStack(10);
+        }
+
+        fn clobberStack(x: i32) void {
+            if (x == 0) return;
+            clobberStack(x - 1);
+            var y: i32 = x;
+        }
+
+        fn bar(f: *@Frame(foo)) void {
+            var pt = Point{ .x = 1, .y = 2 };
+            f.* = async foo(pt);
+            var result = await f;
+            expect(result == 1);
+        }
+
+        fn foo(point: Point) i32 {
+            suspend {
+                frame = @frame();
+            }
+            return point.x;
+        }
+    };
+    S.doTheTest();
+}