0
0
mirror of https://github.com/vim/vim.git synced 2025-10-01 04:54:07 -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

@@ -1845,6 +1845,25 @@ generate_store_var(
return FAIL;
}
/*
* Return TRUE when inside a "for" or "while" loop.
*/
int
inside_loop_scope(cctx_T *cctx)
{
scope_T *scope = cctx->ctx_scope;
for (;;)
{
if (scope == NULL)
break;
if (scope->se_type == FOR_SCOPE || scope->se_type == WHILE_SCOPE)
return TRUE;
scope = scope->se_outer;
}
return FALSE;
}
int
generate_store_lhs(cctx_T *cctx, lhs_T *lhs, int instr_count, int is_decl)
{
@@ -1869,8 +1888,9 @@ generate_store_lhs(cctx_T *cctx, lhs_T *lhs, int instr_count, int is_decl)
varnumber_T val = isn->isn_arg.number;
garray_T *stack = &cctx->ctx_type_stack;
if (val == 0 && is_decl)
if (val == 0 && is_decl && !inside_loop_scope(cctx))
{
// zero is the default value, no need to do anything
--instr->ga_len;
}
else