@@ -55,6 +55,7 @@ func_tbl_get(void)
5555 * Get one function argument.
5656 * If "argtypes" is not NULL also get the type: "arg: type".
5757 * If "types_optional" is TRUE a missing type is OK, use "any".
58+ * If "evalarg" is not NULL use it to check for an already declared name.
5859 * Return a pointer to after the type.
5960 * When something is wrong return "arg".
6061 */
@@ -64,6 +65,7 @@ one_function_arg(
6465 garray_T * newargs ,
6566 garray_T * argtypes ,
6667 int types_optional ,
68+ evalarg_T * evalarg ,
6769 int skip )
6870{
6971 char_u * p = arg ;
@@ -81,13 +83,11 @@ one_function_arg(
8183 return arg ;
8284 }
8385
84- // Vim9 script: cannot use script var name for argument.
85- if (!skip && argtypes != NULL && script_var_exists (arg , p - arg ,
86- FALSE, NULL ) == OK )
87- {
88- semsg (_ (e_variable_already_declared_in_script ), arg );
86+ // Vim9 script: cannot use script var name for argument. In function: also
87+ // check local vars and arguments.
88+ if (!skip && argtypes != NULL && check_defined (arg , p - arg ,
89+ evalarg == NULL ? NULL : evalarg -> eval_cctx , TRUE) == FAIL )
8990 return arg ;
90- }
9191
9292 if (newargs != NULL && ga_grow (newargs , 1 ) == FAIL )
9393 return arg ;
@@ -173,6 +173,7 @@ get_function_args(
173173 garray_T * newargs ,
174174 garray_T * argtypes , // NULL unless using :def
175175 int types_optional , // types optional if "argtypes" is not NULL
176+ evalarg_T * evalarg , // context or NULL
176177 int * varargs ,
177178 garray_T * default_args ,
178179 int skip ,
@@ -247,7 +248,7 @@ get_function_args(
247248
248249 arg = p ;
249250 p = one_function_arg (p , newargs , argtypes , types_optional ,
250- skip );
251+ evalarg , skip );
251252 if (p == arg )
252253 break ;
253254 if (* skipwhite (p ) == '=' )
@@ -260,7 +261,8 @@ get_function_args(
260261 else
261262 {
262263 arg = p ;
263- p = one_function_arg (p , newargs , argtypes , types_optional , skip );
264+ p = one_function_arg (p , newargs , argtypes , types_optional ,
265+ evalarg , skip );
264266 if (p == arg )
265267 break ;
266268
@@ -576,7 +578,7 @@ get_lambda_tv(
576578 // be found after the arguments.
577579 s = * arg + 1 ;
578580 ret = get_function_args (& s , equal_arrow ? ')' : '-' , NULL ,
579- types_optional ? & argtypes : NULL , types_optional ,
581+ types_optional ? & argtypes : NULL , types_optional , evalarg ,
580582 NULL , NULL , TRUE, NULL , NULL );
581583 if (ret == FAIL || skip_arrow (s , equal_arrow , & ret_type , NULL ) == NULL )
582584 {
@@ -592,7 +594,7 @@ get_lambda_tv(
592594 pnewargs = NULL ;
593595 * arg += 1 ;
594596 ret = get_function_args (arg , equal_arrow ? ')' : '-' , pnewargs ,
595- types_optional ? & argtypes : NULL , types_optional ,
597+ types_optional ? & argtypes : NULL , types_optional , evalarg ,
596598 & varargs , NULL , FALSE, NULL , NULL );
597599 if (ret == FAIL
598600 || (s = skip_arrow (* arg , equal_arrow , & ret_type ,
@@ -683,7 +685,6 @@ get_lambda_tv(
683685
684686 fp -> uf_refcount = 1 ;
685687 set_ufunc_name (fp , name );
686- hash_add (& func_hashtab , UF2HIKEY (fp ));
687688 fp -> uf_args = newargs ;
688689 ga_init (& fp -> uf_def_args );
689690 if (types_optional )
@@ -726,6 +727,8 @@ get_lambda_tv(
726727 pt -> pt_refcount = 1 ;
727728 rettv -> vval .v_partial = pt ;
728729 rettv -> v_type = VAR_PARTIAL ;
730+
731+ hash_add (& func_hashtab , UF2HIKEY (fp ));
729732 }
730733
731734 eval_lavars_used = old_eval_lavars ;
@@ -3278,7 +3281,7 @@ define_function(exarg_T *eap, char_u *name_arg)
32783281 ++ p ;
32793282 if (get_function_args (& p , ')' , & newargs ,
32803283 eap -> cmdidx == CMD_def ? & argtypes : NULL , FALSE,
3281- & varargs , & default_args , eap -> skip ,
3284+ NULL , & varargs , & default_args , eap -> skip ,
32823285 eap , & line_to_free ) == FAIL )
32833286 goto errret_2 ;
32843287 whitep = p ;
0 commit comments