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.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 5530056..1a1190e 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -54,6 +54,7 @@
{
*lvar = *lvp;
lvar->lv_from_outer = 0;
+ lvar->lv_loop_idx = get_loop_var_idx(cctx);
}
return OK;
}
@@ -954,7 +955,8 @@
// 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 @@
{
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);
}