diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-09-19 15:54:34 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-09-19 15:54:34 +0100 |
commit | cc34181f9994d64f8c8fa2f5845eaf0cc963067f (patch) | |
tree | 2909cd6f0d4d5f7e20b7daa76855c25fdef5dcb9 /src/structs.h | |
parent | 18ee0feb5dfbe51993dc715d24cf419ac92ebf92 (diff) | |
download | vim-git-cc34181f9994d64f8c8fa2f5845eaf0cc963067f.tar.gz |
patch 9.0.0502: a closure in a nested loop in a :def function does not workv9.0.0502
Problem: A closure in a nested loop in a :def function does not work.
Solution: Use an array of loopvars, one per loop level.
Diffstat (limited to 'src/structs.h')
-rw-r--r-- | src/structs.h | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/structs.h b/src/structs.h index c532dde44..e46446d4d 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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; /* |