authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-16 13:56:26-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-16 13:56:26-04:00
logcbca6586e72a8adefb3d8923d0c0f4590f54bfd8
tree3788f3c5bce090378fe435e56f79a6f85d2d07c2
parent5a2cbe239f4299b4412209148131a501ec023ceb
signaturelock-open Commit is signed but in an unrecognized format.

add test for struct parameter to async function being copied

closes #1155

1 files changed, 43 insertions(+), 0 deletions(-)

test/stage1/behavior/async_fn.zig+43
......@@ -774,3 +774,46 @@ test "return from suspend block" {
774774 };
775775 _ = async S.doTheTest();
776776}
777
778test "struct parameter to async function is copied to the frame" {
779 const S = struct {
780 const Point = struct {
781 x: i32,
782 y: i32,
783 };
784
785 var frame: anyframe = undefined;
786
787 fn doTheTest() void {
788 _ = async atest();
789 resume frame;
790 }
791
792 fn atest() void {
793 var f: @Frame(foo) = undefined;
794 bar(&f);
795 clobberStack(10);
796 }
797
798 fn clobberStack(x: i32) void {
799 if (x == 0) return;
800 clobberStack(x - 1);
801 var y: i32 = x;
802 }
803
804 fn bar(f: *@Frame(foo)) void {
805 var pt = Point{ .x = 1, .y = 2 };
806 f.* = async foo(pt);
807 var result = await f;
808 expect(result == 1);
809 }
810
811 fn foo(point: Point) i32 {
812 suspend {
813 frame = @frame();
814 }
815 return point.x;
816 }
817 };
818 S.doTheTest();
819}