@@ -344,13 +344,29 @@ dict_copy(dict_T *orig, int deep, int copyID)
344344 return copy ;
345345}
346346
347+ /*
348+ * Check for adding a function to g: or s:.
349+ * If the name is wrong give an error message and return TRUE.
350+ */
351+ int
352+ dict_wrong_func_name (dict_T * d , typval_T * tv , char_u * name )
353+ {
354+ return (d == get_globvar_dict ()
355+ || (SCRIPT_ID_VALID (current_sctx .sc_sid )
356+ && d == & SCRIPT_ITEM (current_sctx .sc_sid )-> sn_vars -> sv_dict ))
357+ && (tv -> v_type == VAR_FUNC || tv -> v_type == VAR_PARTIAL )
358+ && var_wrong_func_name (name , TRUE);
359+ }
360+
347361/*
348362 * Add item "item" to Dictionary "d".
349363 * Returns FAIL when out of memory and when key already exists.
350364 */
351365 int
352366dict_add (dict_T * d , dictitem_T * item )
353367{
368+ if (dict_wrong_func_name (d , & item -> di_tv , item -> di_key ))
369+ return FAIL ;
354370 return hash_add (& d -> dv_hashtab , item -> di_key );
355371}
356372
@@ -1109,6 +1125,8 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action)
11091125 if (value_check_lock (di1 -> di_tv .v_lock , arg_errmsg , TRUE)
11101126 || var_check_ro (di1 -> di_flags , arg_errmsg , TRUE))
11111127 break ;
1128+ if (dict_wrong_func_name (d1 , & HI2DI (hi2 )-> di_tv , hi2 -> hi_key ))
1129+ break ;
11121130 clear_tv (& di1 -> di_tv );
11131131 copy_tv (& HI2DI (hi2 )-> di_tv , & di1 -> di_tv );
11141132 }
0 commit comments