0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 9.0.0481: in :def function all closures in loop get the same variables

Problem:    In a :def function all closures in a loop get the same variables.
Solution:   Use a separate list of variables for LOADOUTER and STOREOUTER.
            Not copied at end of loop yet.
This commit is contained in:
Bram Moolenaar
2022-09-16 19:04:24 +01:00
parent abd58d8aee
commit 8fa745e7be
13 changed files with 285 additions and 77 deletions

View File

@@ -54,6 +54,7 @@ lookup_local(char_u *name, size_t len, lvar_T *lvar, cctx_T *cctx)
{
*lvar = *lvp;
lvar->lv_from_outer = 0;
lvar->lv_loop_idx = get_loop_var_idx(cctx);
}
return OK;
}
@@ -954,7 +955,8 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free)
// recursive call.
if (is_global)
{
r = generate_NEWFUNC(cctx, lambda_name, func_name);
// TODO: loop variable index and count
r = generate_NEWFUNC(cctx, lambda_name, func_name, 0, 0);
func_name = NULL;
lambda_name = NULL;
}
@@ -1193,7 +1195,7 @@ generate_loadvar(
{
if (lvar->lv_from_outer > 0)
generate_LOADOUTER(cctx, lvar->lv_idx, lvar->lv_from_outer,
type);
lvar->lv_loop_idx, type);
else
generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type);
}