authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-03 02:40:38-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-03 02:40:38-04:00
logc87920966133d3285b60ccd022282e3f53789e0c
treef8991e5faf1bfa4ebfb943bb0e20b13ccdacad56
parente444e737b786afd0c5aba2ea04c901f89c57813e
signature Commit is signed but in an unrecognized format.

add compile error for calling async function pointer


2 files changed, 17 insertions(+), 1 deletions(-)

src/analyze.cpp+5-1
......@@ -5177,7 +5177,11 @@ static Error resolve_coro_frame(CodeGen *g, ZigType *frame_type) {
51775177 for (size_t i = 0; i < fn->call_list.length; i += 1) {
51785178 IrInstructionCallGen *call = fn->call_list.at(i);
51795179 ZigFn *callee = call->fn_entry;
5180 assert(callee != nullptr);
5180 if (callee == nullptr) {
5181 add_node_error(g, call->base.source_node,
5182 buf_sprintf("function is not comptime-known; @asyncCall required"));
5183 return ErrorSemanticAnalyzeFail;
5184 }
51815185
51825186 analyze_fn_body(g, callee);
51835187 if (callee->anal_state == FnAnalStateInvalid) {
test/compile_errors.zig+12
......@@ -2,6 +2,18 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add(
6 "runtime-known async function called",
7 \\export fn entry() void {
8 \\ var ptr = afunc;
9 \\ _ = ptr();
10 \\}
11 \\
12 \\async fn afunc() void {}
13 ,
14 "tmp.zig:3:12: error: function is not comptime-known; @asyncCall required",
15 );
16
517 cases.add(
618 "runtime-known function called with async keyword",
719 \\export fn entry() void {