@@ -1941,16 +1941,18 @@ find_func_with_prefix(char_u *name, int sid)
19411941
19421942/*
19431943 * Find a function by name, return pointer to it in ufuncs.
1944- * When "is_global" is true don't find script-local or imported functions.
1944+ * When "flags" has FFED_IS_GLOBAL don't find script-local or imported
1945+ * functions.
1946+ * When "flags" has "FFED_NO_GLOBAL" don't find global functions.
19451947 * Return NULL for unknown function.
19461948 */
19471949 ufunc_T *
1948- find_func_even_dead (char_u * name , int is_global )
1950+ find_func_even_dead (char_u * name , int flags )
19491951{
19501952 hashitem_T * hi ;
19511953 ufunc_T * func ;
19521954
1953- if (! is_global )
1955+ if (( flags & FFED_IS_GLOBAL ) == 0 )
19541956 {
19551957 int find_script_local = in_vim9script () && eval_isnamec1 (* name )
19561958 && (name [1 ] != ':' || * name == 's' );
@@ -1965,10 +1967,13 @@ find_func_even_dead(char_u *name, int is_global)
19651967 }
19661968 }
19671969
1968- hi = hash_find (& func_hashtab ,
1970+ if ((flags & FFED_NO_GLOBAL ) == 0 )
1971+ {
1972+ hi = hash_find (& func_hashtab ,
19691973 STRNCMP (name , "g:" , 2 ) == 0 ? name + 2 : name );
1970- if (!HASHITEM_EMPTY (hi ))
1971- return HI2UF (hi );
1974+ if (!HASHITEM_EMPTY (hi ))
1975+ return HI2UF (hi );
1976+ }
19721977
19731978 // Find autoload function if this is an autoload script.
19741979 return find_func_with_prefix (name [0 ] == 's' && name [1 ] == ':'
@@ -1983,7 +1988,7 @@ find_func_even_dead(char_u *name, int is_global)
19831988 ufunc_T *
19841989find_func (char_u * name , int is_global )
19851990{
1986- ufunc_T * fp = find_func_even_dead (name , is_global );
1991+ ufunc_T * fp = find_func_even_dead (name , is_global ? FFED_IS_GLOBAL : 0 );
19871992
19881993 if (fp != NULL && (fp -> uf_flags & FC_DEAD ) == 0 )
19891994 return fp ;
@@ -2354,7 +2359,7 @@ func_clear_free(ufunc_T *fp, int force)
23542359 int
23552360copy_func (char_u * lambda , char_u * global , ectx_T * ectx )
23562361{
2357- ufunc_T * ufunc = find_func_even_dead (lambda , TRUE );
2362+ ufunc_T * ufunc = find_func_even_dead (lambda , FFED_IS_GLOBAL );
23582363 ufunc_T * fp = NULL ;
23592364
23602365 if (ufunc == NULL )
@@ -4464,6 +4469,7 @@ define_function(exarg_T *eap, char_u *name_arg, garray_T *lines_to_free)
44644469 hashtab_T * ht ;
44654470 char_u * find_name = name ;
44664471 int var_conflict = FALSE;
4472+ int ffed_flags = is_global ? FFED_IS_GLOBAL : 0 ;
44674473
44684474 v = find_var (name , & ht , TRUE);
44694475 if (v != NULL && (in_vim9script () || v -> di_tv .v_type == VAR_FUNC ))
@@ -4481,6 +4487,9 @@ define_function(exarg_T *eap, char_u *name_arg, garray_T *lines_to_free)
44814487 v = find_var (find_name , & ht , TRUE);
44824488 if (v != NULL )
44834489 var_conflict = TRUE;
4490+ // Only check if the function already exists in the script,
4491+ // global functions can be shadowed.
4492+ ffed_flags |= FFED_NO_GLOBAL ;
44844493 }
44854494 else
44864495 {
@@ -4508,7 +4517,7 @@ define_function(exarg_T *eap, char_u *name_arg, garray_T *lines_to_free)
45084517 goto erret ;
45094518 }
45104519
4511- fp = find_func_even_dead (find_name , is_global );
4520+ fp = find_func_even_dead (find_name , ffed_flags );
45124521 if (vim9script )
45134522 {
45144523 char_u * uname = untrans_function_name (name );
0 commit comments