diff src/vim9expr.c @ 30291:61a688be1899 v9.0.0481

patch 9.0.0481: in :def function all closures in loop get the same variables Commit: https://github.com/vim/vim/commit/8fa745e7be3a791ac25f93ef0227bbc48ade8a37 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Sep 16 19:04:24 2022 +0100 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.
author Bram Moolenaar <Bram@vim.org>
date Fri, 16 Sep 2022 20:15:03 +0200
parents a970b48c25a3
children 029c59bf78f1
line wrap: on
line diff
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -496,6 +496,7 @@ compile_load(
 	int	    idx;
 	int	    gen_load = FALSE;
 	int	    gen_load_outer = 0;
+	int	    outer_loop_idx = -1;
 
 	name = vim_strnsave(*arg, end - *arg);
 	if (name == NULL)
@@ -520,6 +521,7 @@ compile_load(
 	    {
 		type = lvar.lv_type;
 		idx = lvar.lv_idx;
+		outer_loop_idx = lvar.lv_loop_idx;
 		if (lvar.lv_from_outer != 0)
 		    gen_load_outer = lvar.lv_from_outer;
 		else
@@ -544,7 +546,8 @@ compile_load(
 	    res = generate_LOAD(cctx, ISN_LOAD, idx, NULL, type);
 	if (gen_load_outer > 0)
 	{
-	    res = generate_LOADOUTER(cctx, idx, gen_load_outer, type);
+	    res = generate_LOADOUTER(cctx, idx,
+					 gen_load_outer, outer_loop_idx, type);
 	    cctx->ctx_outer_used = TRUE;
 	}
     }