diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-09-21 18:59:14 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-09-21 18:59:14 +0100 |
commit | e8e369a796e110760d033e937b40c84e0c5e8b36 (patch) | |
tree | aaf71aeb71f9bf17a914a8c56322394fe6f30484 /src/ex_eval.c | |
parent | ec5e1483ebda577e0b7f638c485203cd0e479c47 (diff) |
patch 9.0.0535: closure gets wrong value in for loop with two loop variablesv9.0.0535
Problem: Closure gets wrong value in for loop with two loop variables.
Solution: Correctly compute the number of loop variables to clear.
Diffstat (limited to 'src/ex_eval.c')
-rw-r--r-- | src/ex_eval.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/ex_eval.c b/src/ex_eval.c index 9afcb56940..5721b766ee 100644 --- a/src/ex_eval.c +++ b/src/ex_eval.c @@ -1240,8 +1240,14 @@ ex_while(exarg_T *eap) // variable that we reuse every time around. // Do this backwards, so that vars defined in a later round are // found first. - first = cstack->cs_script_var_len[cstack->cs_idx] - + (eap->cmdidx == CMD_while ? 0 : 1); + first = cstack->cs_script_var_len[cstack->cs_idx]; + if (eap->cmdidx == CMD_for) + { + forinfo_T *fi = cstack->cs_forinfo[cstack->cs_idx]; + + first += fi == NULL || fi->fi_varcount == 0 + ? 1 : fi->fi_varcount; + } for (i = si->sn_var_vals.ga_len - 1; i >= first; --i) { svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + i; |