add compile error for calling async function pointer

This commit is contained in:
Andrew Kelley 2019-08-03 02:40:38 -04:00
parent e444e737b7
commit c879209661
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 17 additions and 1 deletions

View File

@ -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) {

View File

@ -2,6 +2,18 @@ const tests = @import("tests.zig");
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 {