zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit c87920966133d3285b60ccd022282e3f53789e0c (tree)
parent e444e737b786afd0c5aba2ea04c901f89c57813e
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat,  3 Aug 2019 02:40:38 -0400

add compile error for calling async function pointer

Diffstat:
Msrc/analyze.cpp | 6+++++-
Mtest/compile_errors.zig | 12++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/analyze.cpp b/src/analyze.cpp @@ -5177,7 +5177,11 @@ static Error resolve_coro_frame(CodeGen *g, ZigType *frame_type) { for (size_t i = 0; i < fn->call_list.length; i += 1) { IrInstructionCallGen *call = fn->call_list.at(i); ZigFn *callee = call->fn_entry; - assert(callee != nullptr); + if (callee == nullptr) { + add_node_error(g, call->base.source_node, + buf_sprintf("function is not comptime-known; @asyncCall required")); + return ErrorSemanticAnalyzeFail; + } analyze_fn_body(g, callee); if (callee->anal_state == FnAnalStateInvalid) { diff --git a/test/compile_errors.zig b/test/compile_errors.zig @@ -3,6 +3,18 @@ const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( + "runtime-known async function called", + \\export fn entry() void { + \\ var ptr = afunc; + \\ _ = ptr(); + \\} + \\ + \\async fn afunc() void {} + , + "tmp.zig:3:12: error: function is not comptime-known; @asyncCall required", + ); + + cases.add( "runtime-known function called with async keyword", \\export fn entry() void { \\ var ptr = afunc;