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/vim9.h b/src/vim9.h
index 1555e4c..51b0346 100644
--- a/src/vim9.h
+++ b/src/vim9.h
@@ -354,16 +354,29 @@
int ul_forceit; // forceit flag
} unlet_T;
+// extra arguments for funcref_T
+typedef struct {
+ char_u *fre_func_name; // function name for legacy function
+ short fre_loop_var_idx; // index of first variable inside loop
+ short fre_loop_var_count; // number of variables inside loop
+} funcref_extra_T;
+
// arguments to ISN_FUNCREF
typedef struct {
- int fr_dfunc_idx; // function index for :def function
- char_u *fr_func_name; // function name for legacy function
+ int fr_dfunc_idx; // function index for :def function
+ funcref_extra_T *fr_extra; // optional extra information
} funcref_T;
// arguments to ISN_NEWFUNC
typedef struct {
- char_u *nf_lambda; // name of the lambda already defined
- char_u *nf_global; // name of the global function to be created
+ char_u *nfa_lambda; // name of the lambda already defined
+ char_u *nfa_global; // name of the global function to be created
+ short nfa_loop_var_idx; // index of first variable inside loop
+ short nfa_loop_var_count; // number of variables inside loop
+} newfuncarg_T;
+
+typedef struct {
+ newfuncarg_T *nf_arg;
} newfunc_T;
// arguments to ISN_CHECKLEN
@@ -401,6 +414,8 @@
int outer_depth; // nesting level, stack frames to go up
} isn_outer_T;
+#define OUTER_LOOP_DEPTH -9 // used for outer_depth for loop variables
+
// arguments to ISN_SUBSTITUTE
typedef struct {
char_u *subs_cmd; // :s command
@@ -677,6 +692,7 @@
char_u *lv_name;
type_T *lv_type;
int lv_idx; // index of the variable on the stack
+ int lv_loop_idx; // index of first variable inside a loop or -1
int lv_from_outer; // nesting level, using ctx_outer scope
int lv_const; // when TRUE cannot be assigned to
int lv_arg; // when TRUE this is an argument