From 962109e855ca99b3b74d6d70327f2ce936bf1419 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 14 Dec 2019 02:33:19 +0300 Subject: [PATCH] parser: verify async functions --- vlib/compiler/fn.v | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index 88a4f061a4..04d040a221 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -645,6 +645,7 @@ fn (p mut Parser) check_unused_and_mut_vars() { // receiver_var - "user" (needed for pthreads) // receiver_type - "User" fn (p mut Parser) async_fn_call(f Fn, method_ph int, receiver_var, receiver_type string) { + p.verify_fn_before_call(f) // println('\nfn_call $f.name is_method=$f.is_method receiver_type=$f.receiver_type') // p.print_tok() mut thread_name := '' @@ -721,10 +722,10 @@ fn (p mut Parser) async_fn_call(f Fn, method_ph int, receiver_var, receiver_type p.genln('int $tmp2 = pthread_create(& $thread_name, NULL, (void *)$wrapper_name, $parg);') } p.check(.rpar) + } -// p.tok == fn_name -fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type string) { +fn (p mut Parser) verify_fn_before_call(f &Fn) { if f.is_unsafe && !p.builtin_mod && !p.inside_unsafe { p.warn('you are calling an unsafe function outside of an unsafe block') } @@ -737,6 +738,11 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s } p.error('function `$f.name` is private') } +} + +// p.tok == fn_name +fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type string) { + p.verify_fn_before_call(f) is_comptime_define := f.comptime_define != '' && f.comptime_define != p.pref.comptime_define if is_comptime_define { p.cgen.nogen = true