diff options
Diffstat (limited to 'src/vim9cmds.c')
| -rw-r--r-- | src/vim9cmds.c | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/src/vim9cmds.c b/src/vim9cmds.c index c294d70a8..080674d2c 100644 --- a/src/vim9cmds.c +++ b/src/vim9cmds.c @@ -1685,33 +1685,12 @@ compile_eval(char_u *arg, cctx_T *cctx) } /* - * Get the local variable index for deferred function calls. - * Reserve it when not done already. - * Returns zero for failure. - */ - int -get_defer_var_idx(cctx_T *cctx) -{ - dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) - + cctx->ctx_ufunc->uf_dfunc_idx; - if (dfunc->df_defer_var_idx == 0) - { - lvar_T *lvar = reserve_local(cctx, (char_u *)"@defer@", 7, - TRUE, &t_list_any); - if (lvar == NULL) - return 0; - dfunc->df_defer_var_idx = lvar->lv_idx + 1; - } - return dfunc->df_defer_var_idx; -} - -/* * Compile "defer func(arg)". */ char_u * compile_defer(char_u *arg_start, cctx_T *cctx) { - char_u *p; + char_u *paren; char_u *arg = arg_start; int argcount = 0; int defer_var_idx; @@ -1720,13 +1699,13 @@ compile_defer(char_u *arg_start, cctx_T *cctx) // Get a funcref for the function name. // TODO: better way to find the "(". - p = vim_strchr(arg, '('); - if (p == NULL) + paren = vim_strchr(arg, '('); + if (paren == NULL) { semsg(_(e_missing_parenthesis_str), arg); return NULL; } - *p = NUL; + *paren = NUL; func_idx = find_internal_func(arg); if (func_idx >= 0) // TODO: better type @@ -1734,7 +1713,7 @@ compile_defer(char_u *arg_start, cctx_T *cctx) &t_func_any, FALSE); else if (compile_expr0(&arg, cctx) == FAIL) return NULL; - *p = '('; + *paren = '('; // check for function type type = get_type_on_stack(cctx, 0); @@ -1745,11 +1724,22 @@ compile_defer(char_u *arg_start, cctx_T *cctx) } // compile the arguments - arg = skipwhite(p + 1); + arg = skipwhite(paren + 1); if (compile_arguments(&arg, cctx, &argcount, CA_NOT_SPECIAL) == FAIL) return NULL; - // TODO: check argument count with "type" + if (func_idx >= 0) + { + type2_T *argtypes = NULL; + type2_T shuffled_argtypes[MAX_FUNC_ARGS]; + + if (check_internal_func_args(cctx, func_idx, argcount, FALSE, + &argtypes, shuffled_argtypes) == FAIL) + return NULL; + } + else if (check_func_args_from_type(cctx, type, argcount, TRUE, + arg_start) == FAIL) + return NULL; defer_var_idx = get_defer_var_idx(cctx); if (defer_var_idx == 0) |
