0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

patch 8.2.4912: using execute() to define a lambda doesn't work

Problem:    Using execute() to define a lambda doesn't work. (Ernie Rael)
Solution:   Put the getline function in evalarg. (closes #10375)
This commit is contained in:
Bram Moolenaar 2022-05-07 21:14:05 +01:00
parent 249591057b
commit a7583c42cd
5 changed files with 26 additions and 3 deletions

View File

@ -140,7 +140,7 @@ fill_evalarg_from_eap(evalarg_T *evalarg, exarg_T *eap, int skip)
if (eap != NULL) if (eap != NULL)
{ {
evalarg->eval_cstack = eap->cstack; evalarg->eval_cstack = eap->cstack;
if (sourcing_a_script(eap)) if (sourcing_a_script(eap) || eap->getline == get_list_line)
{ {
evalarg->eval_getline = eap->getline; evalarg->eval_getline = eap->getline;
evalarg->eval_cookie = eap->cookie; evalarg->eval_cookie = eap->cookie;

View File

@ -3868,7 +3868,7 @@ execute_cmds_from_string(char_u *str)
* Called by do_cmdline() to get the next line. * Called by do_cmdline() to get the next line.
* Returns allocated string, or NULL for end of function. * Returns allocated string, or NULL for end of function.
*/ */
static char_u * char_u *
get_list_line( get_list_line(
int c UNUSED, int c UNUSED,
void *cookie, void *cookie,

View File

@ -17,11 +17,12 @@ buf_T *get_buf_arg(typval_T *arg);
win_T *get_optional_window(typval_T *argvars, int idx); win_T *get_optional_window(typval_T *argvars, int idx);
void execute_redir_str(char_u *value, int value_len); void execute_redir_str(char_u *value, int value_len);
void execute_cmds_from_string(char_u *str); void execute_cmds_from_string(char_u *str);
char_u *get_list_line(int c, void *cookie, int indent, getline_opt_T options);
void execute_common(typval_T *argvars, typval_T *rettv, int arg_off); void execute_common(typval_T *argvars, typval_T *rettv, int arg_off);
void f_exists(typval_T *argvars, typval_T *rettv); void f_exists(typval_T *argvars, typval_T *rettv);
void f_has(typval_T *argvars, typval_T *rettv); void f_has(typval_T *argvars, typval_T *rettv);
void f_len(typval_T *argvars, typval_T *rettv);
int dynamic_feature(char_u *feature); int dynamic_feature(char_u *feature);
void f_len(typval_T *argvars, typval_T *rettv);
void mzscheme_call_vim(char_u *name, typval_T *args, typval_T *rettv); void mzscheme_call_vim(char_u *name, typval_T *args, typval_T *rettv);
void range_list_materialize(list_T *list); void range_list_materialize(list_T *list);
long do_searchpair(char_u *spat, char_u *mpat, char_u *epat, int dir, typval_T *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit); long do_searchpair(char_u *spat, char_u *mpat, char_u *epat, int dir, typval_T *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit);

View File

@ -1615,6 +1615,26 @@ def Test_lambda_type_allocated()
v9.CheckScriptSuccess(lines) v9.CheckScriptSuccess(lines)
enddef enddef
def Test_define_lambda_in_execute()
var lines =<< trim [CODE]
vim9script
def BuildFuncMultiLine(): func
var x =<< trim END
g:SomeRandomFunc = (d: dict<any>) => {
return d.k1 + d.k2
}
END
execute(x)
return g:SomeRandomFunc
enddef
var ResultPlus = BuildFuncMultiLine()
assert_equal(7, ResultPlus({k1: 3, k2: 4}))
[CODE]
v9.CheckScriptSuccess(lines)
unlet g:SomeRandomFunc
enddef
" Default arg and varargs " Default arg and varargs
def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string
var res = one .. ',' .. two var res = one .. ',' .. two

View File

@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
4912,
/**/ /**/
4911, 4911,
/**/ /**/