patch 8.2.4103: Vim9: variable declared in for loop not initialzed
Problem: Vim9: variable declared in for loop not initialzed.
Solution: Always initialze the variable. (closes #9535)
diff --git a/src/vim9compile.c b/src/vim9compile.c
index afc7885..89520f9 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2256,12 +2256,17 @@
case VAR_VOID:
case VAR_INSTR:
case VAR_SPECIAL: // cannot happen
- // This is skipped for local variables, they are
- // always initialized to zero.
- if (lhs.lhs_dest == dest_local)
+ // This is skipped for local variables, they are always
+ // initialized to zero. But in a "for" or "while" loop
+ // the value may have been changed.
+ if (lhs.lhs_dest == dest_local
+ && !inside_loop_scope(cctx))
skip_store = TRUE;
else
+ {
+ instr_count = instr->ga_len;
generate_PUSHNR(cctx, 0);
+ }
break;
}
}