0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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)
This commit is contained in:
Bram Moolenaar
2022-01-15 21:44:44 +00:00
parent 857c8bb1bb
commit 38ecd97226
5 changed files with 67 additions and 4 deletions

View File

@@ -2256,12 +2256,17 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
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;
}
}