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/structs.h b/src/structs.h
index be08f0a..22608db 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -1656,7 +1656,7 @@
/*
* Structure to hold info for a user function.
- * When adding a field check copy_func().
+ * When adding a field check copy_lambda_to_global_func().
*/
typedef struct
{
@@ -1741,7 +1741,8 @@
#define FC_NOARGS 0x200 // no a: variables in lambda
#define FC_VIM9 0x400 // defined in vim9 script file
#define FC_CFUNC 0x800 // defined as Lua C func
-#define FC_COPY 0x1000 // copy of another function by copy_func()
+#define FC_COPY 0x1000 // copy of another function by
+ // copy_lambda_to_global_func()
#define FC_LAMBDA 0x2000 // one line "return {expr}"
#define MAX_FUNC_ARGS 20 // maximum number of function arguments
@@ -2096,10 +2097,17 @@
typedef struct outer_S outer_T;
struct outer_S {
- garray_T *out_stack; // stack from outer scope
+ garray_T *out_stack; // stack from outer scope, or a copy
+ // containing only arguments and local vars
int out_frame_idx; // index of stack frame in out_stack
outer_T *out_up; // outer scope of outer scope or NULL
partial_T *out_up_partial; // partial owning out_up or NULL
+
+ garray_T *out_loop_stack; // stack from outer scope, or a copy
+ // containing only vars inside the loop
+ short out_loop_var_idx; // first variable defined in a loop
+ // in out_loop_stack
+ short out_loop_var_count; // number of variables defined in a loop
};
struct partial_S