From 4f594527c02985272d61c198d7c5aafa7d777e50 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 27 Oct 2019 17:31:06 -0400 Subject: [PATCH] detect async fn recursion and emit compile error --- src/analyze.cpp | 7 +++++++ src/codegen.cpp | 1 + 2 files changed, 8 insertions(+) diff --git a/src/analyze.cpp b/src/analyze.cpp index 73ad719627..e9e03466c5 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4398,6 +4398,7 @@ static Error analyze_callee_async(CodeGen *g, ZigFn *fn, ZigFn *callee, AstNode } } if (callee_is_async) { + bool bad_recursion = (fn->inferred_async_node == inferred_async_none); fn->inferred_async_node = call_node; fn->inferred_async_fn = callee; if (must_not_be_async) { @@ -4407,6 +4408,12 @@ static Error analyze_callee_async(CodeGen *g, ZigFn *fn, ZigFn *callee, AstNode add_async_error_notes(g, msg, fn); return ErrorSemanticAnalyzeFail; } + if (bad_recursion) { + ErrorMsg *msg = add_node_error(g, fn->proto_node, + buf_sprintf("recursive function cannot be async")); + add_async_error_notes(g, msg, fn); + return ErrorSemanticAnalyzeFail; + } if (fn->assumed_non_async != nullptr) { ErrorMsg *msg = add_node_error(g, fn->proto_node, buf_sprintf("unable to infer whether '%s' should be async", diff --git a/src/codegen.cpp b/src/codegen.cpp index d01bcfbd77..a172ca39a7 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3917,6 +3917,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr if (instruction->modifier == CallModifierAsync) { frame_result_loc = result_loc; } else { + src_assert(instruction->frame_result_loc != nullptr, instruction->base.source_node); frame_result_loc_uncasted = ir_llvm_value(g, instruction->frame_result_loc); src_assert(instruction->fn_entry != nullptr, instruction->base.source_node); frame_result_loc = LLVMBuildBitCast(g->builder, frame_result_loc_uncasted,