diff src/vim9compile.c @ 26729:b969fdb8cd46 v8.2.3893

patch 8.2.3893: Vim9: many local variables are initialized with an instruction Commit: https://github.com/vim/vim/commit/5cd647935d0834b3064aa36384b8f6730fadadd6 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 25 18:23:24 2021 +0000 patch 8.2.3893: Vim9: many local variables are initialized with an instruction Problem: Vim9: many local variables are initialized with an instruction. Solution: Initialize local variables to zero to avoid the instructions.
author Bram Moolenaar <Bram@vim.org>
date Sat, 25 Dec 2021 19:30:03 +0100
parents 1b288eb2fcdc
children a8a4e1e7b111
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1963,6 +1963,7 @@ compile_assignment(char_u *arg, exarg_T 
     {
 	int	instr_count = -1;
 	int	save_lnum;
+	int	skip_store = FALSE;
 
 	if (var_start[0] == '_' && !eval_isnamec(var_start[1]))
 	{
@@ -2186,7 +2187,12 @@ compile_assignment(char_u *arg, exarg_T 
 		    case VAR_VOID:
 		    case VAR_INSTR:
 		    case VAR_SPECIAL:  // cannot happen
-			generate_PUSHNR(cctx, 0);
+			// This is skipped for local variables, they are
+			// always initialized to zero.
+			if (lhs.lhs_dest == dest_local)
+			    skip_store = TRUE;
+			else
+			    generate_PUSHNR(cctx, 0);
 			break;
 		}
 	    }
@@ -2278,7 +2284,8 @@ compile_assignment(char_u *arg, exarg_T 
 		// type of "val" is used.
 		generate_SETTYPE(cctx, lhs.lhs_type);
 
-	    if (generate_store_lhs(cctx, &lhs, instr_count) == FAIL)
+	    if (!skip_store && generate_store_lhs(cctx, &lhs,
+						 instr_count, is_decl) == FAIL)
 	    {
 		cctx->ctx_lnum = save_lnum;
 		goto theend;