@@ -237,8 +237,8 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate);
237237
238238static int get_env_len (char_u * * arg );
239239static char_u * make_expanded_name (char_u * in_start , char_u * expr_start , char_u * expr_end , char_u * in_end );
240+ static void check_vars (char_u * name , int len );
240241static typval_T * alloc_string_tv (char_u * string );
241- static hashtab_T * find_var_ht (char_u * name , char_u * * varname );
242242static void delete_var (hashtab_T * ht , hashitem_T * hi );
243243static void list_one_var (dictitem_T * v , char_u * prefix , int * first );
244244static void list_one_var_a (char_u * prefix , char_u * name , int type , char_u * string , int * first );
@@ -2837,7 +2837,9 @@ do_unlet(char_u *name, int forceit)
28372837 }
28382838 }
28392839 hi = hash_find (ht , varname );
2840- if (!HASHITEM_EMPTY (hi ))
2840+ if (HASHITEM_EMPTY (hi ))
2841+ hi = find_hi_in_scoped_ht (name , & varname , & ht );
2842+ if (hi != NULL && !HASHITEM_EMPTY (hi ))
28412843 {
28422844 di = HI2DI (hi );
28432845 if (var_check_fixed (di -> di_flags , name , FALSE)
@@ -4332,6 +4334,9 @@ eval7(
43324334 {
43334335 partial_T * partial ;
43344336
4337+ if (!evaluate )
4338+ check_vars (s , len );
4339+
43354340 /* If "s" is the name of a variable of type VAR_FUNC
43364341 * use its contents. */
43374342 s = deref_func_name (s , & len , & partial , !evaluate );
@@ -4363,7 +4368,10 @@ eval7(
43634368 else if (evaluate )
43644369 ret = get_var_tv (s , len , rettv , NULL , TRUE, FALSE);
43654370 else
4371+ {
4372+ check_vars (s , len );
43664373 ret = OK ;
4374+ }
43674375 }
43684376 vim_free (alias );
43694377 }
@@ -5540,6 +5548,10 @@ set_ref_in_item(
55405548 }
55415549 }
55425550 }
5551+ else if (tv -> v_type == VAR_FUNC )
5552+ {
5553+ abort = set_ref_in_func (tv -> vval .v_string , copyID );
5554+ }
55435555 else if (tv -> v_type == VAR_PARTIAL )
55445556 {
55455557 partial_T * pt = tv -> vval .v_partial ;
@@ -5549,6 +5561,8 @@ set_ref_in_item(
55495561 */
55505562 if (pt != NULL )
55515563 {
5564+ abort = set_ref_in_func (pt -> pt_name , copyID );
5565+
55525566 if (pt -> pt_dict != NULL )
55535567 {
55545568 typval_T dtv ;
@@ -6790,6 +6804,34 @@ get_var_tv(
67906804 return ret ;
67916805}
67926806
6807+ /*
6808+ * Check if variable "name[len]" is a local variable or an argument.
6809+ * If so, "*eval_lavars_used" is set to TRUE.
6810+ */
6811+ static void
6812+ check_vars (char_u * name , int len )
6813+ {
6814+ int cc ;
6815+ char_u * varname ;
6816+ hashtab_T * ht ;
6817+
6818+ if (eval_lavars_used == NULL )
6819+ return ;
6820+
6821+ /* truncate the name, so that we can use strcmp() */
6822+ cc = name [len ];
6823+ name [len ] = NUL ;
6824+
6825+ ht = find_var_ht (name , & varname );
6826+ if (ht == get_funccal_local_ht () || ht == get_funccal_args_ht ())
6827+ {
6828+ if (find_var (name , NULL , TRUE) != NULL )
6829+ * eval_lavars_used = TRUE;
6830+ }
6831+
6832+ name [len ] = cc ;
6833+ }
6834+
67936835/*
67946836 * Handle expr[expr], expr[expr:expr] subscript and .name lookup.
67956837 * Also handle function call with Funcref variable: func(expr)
@@ -7274,13 +7316,20 @@ find_var(char_u *name, hashtab_T **htp, int no_autoload)
72747316{
72757317 char_u * varname ;
72767318 hashtab_T * ht ;
7319+ dictitem_T * ret = NULL ;
72777320
72787321 ht = find_var_ht (name , & varname );
72797322 if (htp != NULL )
72807323 * htp = ht ;
72817324 if (ht == NULL )
72827325 return NULL ;
7283- return find_var_in_ht (ht , * name , varname , no_autoload || htp != NULL );
7326+ ret = find_var_in_ht (ht , * name , varname , no_autoload || htp != NULL );
7327+ if (ret != NULL )
7328+ return ret ;
7329+
7330+ /* Search in parent scope for lambda */
7331+ return find_var_in_scoped_ht (name , varname ? & varname : NULL ,
7332+ no_autoload || htp != NULL );
72847333}
72857334
72867335/*
@@ -7341,7 +7390,7 @@ find_var_in_ht(
73417390 * Return NULL if the name is not valid.
73427391 * Set "varname" to the start of name without ':'.
73437392 */
7344- static hashtab_T *
7393+ hashtab_T *
73457394find_var_ht (char_u * name , char_u * * varname )
73467395{
73477396 hashitem_T * hi ;
@@ -7617,6 +7666,10 @@ set_var(
76177666 }
76187667 v = find_var_in_ht (ht , 0 , varname , TRUE);
76197668
7669+ /* Search in parent scope which is possible to reference from lambda */
7670+ if (v == NULL )
7671+ v = find_var_in_scoped_ht (name , varname ? & varname : NULL , TRUE);
7672+
76207673 if ((tv -> v_type == VAR_FUNC || tv -> v_type == VAR_PARTIAL )
76217674 && var_check_func_name (name , v == NULL ))
76227675 return ;
0 commit comments