Skip to content

Commit

Permalink
fix and test case for returning from suspend block
Browse files Browse the repository at this point in the history
See #3063
  • Loading branch information
andrewrk committed Aug 16, 2019
1 parent 2cb1f93 commit 5a2cbe2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");
if (fn_is_async(g->cur_fn)) {
instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");
}
return nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions test/stage1/behavior/async_fn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 5a2cbe2

Please sign in to comment.