Mercurial > vim
diff src/vim9compile.c @ 27148:6ed31017c303 v8.2.4103
patch 8.2.4103: Vim9: variable declared in for loop not initialzed
Commit: https://github.com/vim/vim/commit/38ecd9722664049d636f4fba759b3ebbfd34e97d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 15 21:44:44 2022 +0000
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 https://github.com/vim/vim/issues/9535)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 15 Jan 2022 22:45:03 +0100 |
parents | 0e88b48575ee |
children | 44cb142c8615 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -2256,12 +2256,17 @@ compile_assignment(char_u *arg, exarg_T 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; } }