fix and test case for returning from suspend block

See #3063
master
Andrew Kelley 2019-08-16 13:00:48 -04:00
parent 2cb1f93894
commit 5a2cbe239f
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
3 changed files with 18 additions and 2 deletions

View File

@ -5470,7 +5470,9 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab
static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable,
IrInstructionSuspendBegin *instruction)
{
if (fn_is_async(g->cur_fn)) {
instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");
}
return nullptr;
}

View File

@ -7914,7 +7914,7 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod
ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));
}
return ir_build_suspend_finish(irb, parent_scope, node, begin);
return ir_mark_gen(ir_build_suspend_finish(irb, parent_scope, node, begin));
}
static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,

View File

@ -760,3 +760,17 @@ test "async call a generic function" {
};
_ = async S.doTheTest();
}
test "return from suspend block" {
const S = struct {
fn doTheTest() void {
expect(func() == 1234);
}
fn func() i32 {
suspend {
return 1234;
}
}
};
_ = async S.doTheTest();
}