0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

patch 9.0.0535: closure gets wrong value in for loop with two loop variables

Problem:    Closure gets wrong value in for loop with two loop variables.
Solution:   Correctly compute the number of loop variables to clear.
This commit is contained in:
Bram Moolenaar
2022-09-21 18:59:14 +01:00
parent ec5e1483eb
commit e8e369a796
5 changed files with 34 additions and 5 deletions

View File

@@ -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;