summaryrefslogtreecommitdiffstats
path: root/src/ex_eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-11-22 18:31:02 +0000
committerBram Moolenaar <Bram@vim.org>2021-11-22 18:31:02 +0000
commit7a53f29c031f54ab67a803e5e3f8cb44e4edc4bc (patch)
tree7d2a143dc72f6fe415c7efba4d79faad3e413e1c /src/ex_eval.c
parent4671e88d7d3ed12206d9cdd8892fe3b2cbc0d6ab (diff)
patch 8.2.3649: Vim9: error for variable declared in while loopv8.2.3649
Problem: Vim9: error for variable declared in while loop. Solution: Do not keep the first variable. (closes #9191)
Diffstat (limited to 'src/ex_eval.c')
-rw-r--r--src/ex_eval.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/ex_eval.c b/src/ex_eval.c
index d80500eb0b..4e38e96491 100644
--- a/src/ex_eval.c
+++ b/src/ex_eval.c
@@ -1201,9 +1201,10 @@ ex_while(exarg_T *eap)
& CSF_FUNC_DEF;
// Any variables defined in the previous round are no longer
- // visible. Keep the first one, it is the loop variable that
- // we reuse every time around.
- for (i = cstack->cs_script_var_len[cstack->cs_idx] + 1;
+ // visible. Keep the first one for ":for", it is the loop
+ // variable that we reuse every time around.
+ for (i = cstack->cs_script_var_len[cstack->cs_idx]
+ + (eap->cmdidx == CMD_while ? 0 : 1);
i < si->sn_var_vals.ga_len; ++i)
{
svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + i;