0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -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

@@ -354,16 +354,29 @@ typedef struct {
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 @@ typedef struct {
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 @@ typedef struct {
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