0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 9.0.0502: a closure in a nested loop in a :def function does not work

Problem:    A closure in a nested loop in a :def function does not work.
Solution:   Use an array of loopvars, one per loop level.
This commit is contained in:
Bram Moolenaar
2022-09-19 15:54:34 +01:00
parent 18ee0feb5d
commit cc34181f99
15 changed files with 398 additions and 182 deletions

View File

@@ -2108,6 +2108,9 @@ struct loopvars_S
int lvs_copyID; // for garbage collection
};
// maximum nesting of :while and :for loops in a :def function
#define MAX_LOOP_DEPTH 10
typedef struct outer_S outer_T;
struct outer_S {
garray_T *out_stack; // stack from outer scope, or a copy
@@ -2116,11 +2119,13 @@ struct outer_S {
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
struct {
garray_T *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
short var_idx; // first variable defined in a loop in
// out_loop_stack
short var_count; // number of variables defined in a loop
} out_loop[MAX_LOOP_DEPTH];
};
struct partial_S
@@ -2141,7 +2146,8 @@ struct partial_S
funcstack_T *pt_funcstack; // copy of stack, used after context
// function returns
loopvars_T *pt_loopvars; // copy of loop variables, used after loop
loopvars_T *(pt_loopvars[MAX_LOOP_DEPTH]);
// copy of loop variables, used after loop
// block ends
typval_T *pt_argv; // arguments in allocated array
@@ -2151,6 +2157,14 @@ struct partial_S
dict_T *pt_dict; // dict for "self"
};
typedef struct {
short lvi_depth; // current nested loop depth
struct {
short var_idx; // index of first variable inside loop
short var_count; // number of variables inside loop
} lvi_loop[MAX_LOOP_DEPTH];
} loopvarinfo_T;
typedef struct AutoPatCmd_S AutoPatCmd_T;
/*