@@ -1684,34 +1684,13 @@ compile_eval(char_u *arg, cctx_T *cctx)
16841684 return skipwhite (p );
16851685}
16861686
1687- /*
1688- * Get the local variable index for deferred function calls.
1689- * Reserve it when not done already.
1690- * Returns zero for failure.
1691- */
1692- int
1693- get_defer_var_idx (cctx_T * cctx )
1694- {
1695- dfunc_T * dfunc = ((dfunc_T * )def_functions .ga_data )
1696- + cctx -> ctx_ufunc -> uf_dfunc_idx ;
1697- if (dfunc -> df_defer_var_idx == 0 )
1698- {
1699- lvar_T * lvar = reserve_local (cctx , (char_u * )"@defer@" , 7 ,
1700- TRUE, & t_list_any );
1701- if (lvar == NULL )
1702- return 0 ;
1703- dfunc -> df_defer_var_idx = lvar -> lv_idx + 1 ;
1704- }
1705- return dfunc -> df_defer_var_idx ;
1706- }
1707-
17081687/*
17091688 * Compile "defer func(arg)".
17101689 */
17111690 char_u *
17121691compile_defer (char_u * arg_start , cctx_T * cctx )
17131692{
1714- char_u * p ;
1693+ char_u * paren ;
17151694 char_u * arg = arg_start ;
17161695 int argcount = 0 ;
17171696 int defer_var_idx ;
@@ -1720,21 +1699,21 @@ compile_defer(char_u *arg_start, cctx_T *cctx)
17201699
17211700 // Get a funcref for the function name.
17221701 // TODO: better way to find the "(".
1723- p = vim_strchr (arg , '(' );
1724- if (p == NULL )
1702+ paren = vim_strchr (arg , '(' );
1703+ if (paren == NULL )
17251704 {
17261705 semsg (_ (e_missing_parenthesis_str ), arg );
17271706 return NULL ;
17281707 }
1729- * p = NUL ;
1708+ * paren = NUL ;
17301709 func_idx = find_internal_func (arg );
17311710 if (func_idx >= 0 )
17321711 // TODO: better type
17331712 generate_PUSHFUNC (cctx , (char_u * )internal_func_name (func_idx ),
17341713 & t_func_any , FALSE);
17351714 else if (compile_expr0 (& arg , cctx ) == FAIL )
17361715 return NULL ;
1737- * p = '(' ;
1716+ * paren = '(' ;
17381717
17391718 // check for function type
17401719 type = get_type_on_stack (cctx , 0 );
@@ -1745,11 +1724,22 @@ compile_defer(char_u *arg_start, cctx_T *cctx)
17451724 }
17461725
17471726 // compile the arguments
1748- arg = skipwhite (p + 1 );
1727+ arg = skipwhite (paren + 1 );
17491728 if (compile_arguments (& arg , cctx , & argcount , CA_NOT_SPECIAL ) == FAIL )
17501729 return NULL ;
17511730
1752- // TODO: check argument count with "type"
1731+ if (func_idx >= 0 )
1732+ {
1733+ type2_T * argtypes = NULL ;
1734+ type2_T shuffled_argtypes [MAX_FUNC_ARGS ];
1735+
1736+ if (check_internal_func_args (cctx , func_idx , argcount , FALSE,
1737+ & argtypes , shuffled_argtypes ) == FAIL )
1738+ return NULL ;
1739+ }
1740+ else if (check_func_args_from_type (cctx , type , argcount , TRUE,
1741+ arg_start ) == FAIL )
1742+ return NULL ;
17531743
17541744 defer_var_idx = get_defer_var_idx (cctx );
17551745 if (defer_var_idx == 0 )
0 commit comments