@@ -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 );
@@ -4332,6 +4332,9 @@ eval7(
43324332 {
43334333 partial_T * partial ;
43344334
4335+ if (!evaluate )
4336+ check_vars (s , len );
4337+
43354338 /* If "s" is the name of a variable of type VAR_FUNC
43364339 * use its contents. */
43374340 s = deref_func_name (s , & len , & partial , !evaluate );
@@ -4363,7 +4366,10 @@ eval7(
43634366 else if (evaluate )
43644367 ret = get_var_tv (s , len , rettv , NULL , TRUE, FALSE);
43654368 else
4369+ {
4370+ check_vars (s , len );
43664371 ret = OK ;
4372+ }
43674373 }
43684374 vim_free (alias );
43694375 }
@@ -5540,6 +5546,10 @@ set_ref_in_item(
55405546 }
55415547 }
55425548 }
5549+ else if (tv -> v_type == VAR_FUNC )
5550+ {
5551+ abort = set_ref_in_func (tv -> vval .v_string , copyID );
5552+ }
55435553 else if (tv -> v_type == VAR_PARTIAL )
55445554 {
55455555 partial_T * pt = tv -> vval .v_partial ;
@@ -5549,6 +5559,8 @@ set_ref_in_item(
55495559 */
55505560 if (pt != NULL )
55515561 {
5562+ abort = set_ref_in_func (pt -> pt_name , copyID );
5563+
55525564 if (pt -> pt_dict != NULL )
55535565 {
55545566 typval_T dtv ;
@@ -6790,6 +6802,34 @@ get_var_tv(
67906802 return ret ;
67916803}
67926804
6805+ /*
6806+ * Check if variable "name[len]" is a local variable or an argument.
6807+ * If so, "*eval_lavars_used" is set to TRUE.
6808+ */
6809+ static void
6810+ check_vars (char_u * name , int len )
6811+ {
6812+ int cc ;
6813+ char_u * varname ;
6814+ hashtab_T * ht ;
6815+
6816+ if (eval_lavars_used == NULL )
6817+ return ;
6818+
6819+ /* truncate the name, so that we can use strcmp() */
6820+ cc = name [len ];
6821+ name [len ] = NUL ;
6822+
6823+ ht = find_var_ht (name , & varname );
6824+ if (ht == get_funccal_local_ht () || ht == get_funccal_args_ht ())
6825+ {
6826+ if (find_var (name , NULL , TRUE) != NULL )
6827+ * eval_lavars_used = TRUE;
6828+ }
6829+
6830+ name [len ] = cc ;
6831+ }
6832+
67936833/*
67946834 * Handle expr[expr], expr[expr:expr] subscript and .name lookup.
67956835 * Also handle function call with Funcref variable: func(expr)
@@ -7274,13 +7314,20 @@ find_var(char_u *name, hashtab_T **htp, int no_autoload)
72747314{
72757315 char_u * varname ;
72767316 hashtab_T * ht ;
7317+ dictitem_T * ret = NULL ;
72777318
72787319 ht = find_var_ht (name , & varname );
72797320 if (htp != NULL )
72807321 * htp = ht ;
72817322 if (ht == NULL )
72827323 return NULL ;
7283- return find_var_in_ht (ht , * name , varname , no_autoload || htp != NULL );
7324+ ret = find_var_in_ht (ht , * name , varname , no_autoload || htp != NULL );
7325+ if (ret != NULL )
7326+ return ret ;
7327+
7328+ /* Search in parent scope for lambda */
7329+ return find_var_in_scoped_ht (name , varname ? & varname : NULL ,
7330+ no_autoload || htp != NULL );
72847331}
72857332
72867333/*
@@ -7341,7 +7388,7 @@ find_var_in_ht(
73417388 * Return NULL if the name is not valid.
73427389 * Set "varname" to the start of name without ':'.
73437390 */
7344- static hashtab_T *
7391+ hashtab_T *
73457392find_var_ht (char_u * name , char_u * * varname )
73467393{
73477394 hashitem_T * hi ;
@@ -7617,6 +7664,10 @@ set_var(
76177664 }
76187665 v = find_var_in_ht (ht , 0 , varname , TRUE);
76197666
7667+ /* Search in parent scope which is possible to reference from lambda */
7668+ if (v == NULL )
7669+ v = find_var_in_scoped_ht (name , varname ? & varname : NULL , TRUE);
7670+
76207671 if ((tv -> v_type == VAR_FUNC || tv -> v_type == VAR_PARTIAL )
76217672 && var_check_func_name (name , v == NULL ))
76227673 return ;
0 commit comments