add test for struct parameter to async function being copied

closes #1155
This commit is contained in:
Andrew Kelley 2019-08-16 13:56:26 -04:00
parent 5a2cbe239f
commit cbca6586e7
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -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();
}