]> granicus.if.org Git - vim/commitdiff
patch 8.2.3511: Vim9: entry for loop variable is created every round v8.2.3511
authorBram Moolenaar <Bram@vim.org>
Thu, 14 Oct 2021 23:18:37 +0000 (00:18 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 14 Oct 2021 23:18:37 +0000 (00:18 +0100)
Problem:    Vim9: entry for loop variable is created every round.
Solution:   Only create the entry once. (closes #8996)

src/evalvars.c
src/version.c
src/vim9script.c

index 4cc0fa8e34e4c6f323c34785c5f1e37946e07077..fbf2d68d1b9888b8a0efe1edecf147bf8074d22a 100644 (file)
@@ -3319,7 +3319,7 @@ set_var_const(
                    goto failed;
                }
 
-               if (var_in_vim9script)
+               if (var_in_vim9script && (flags & ASSIGN_FOR_LOOP) == 0)
                {
                    where_T where = WHERE_INIT;
 
@@ -3331,7 +3331,8 @@ set_var_const(
                        goto failed;
                }
 
-               if (var_check_permission(di, name) == FAIL)
+               if ((flags & ASSIGN_FOR_LOOP) == 0
+                                    && var_check_permission(di, name) == FAIL)
                    goto failed;
            }
            else
index d1f079cb280d0b40c05ee2e8f1ff5ae5a91cf4ef..f4e9f9f921837c93b406e4603fcc17ff40d6b172 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3511,
 /**/
     3510,
 /**/
index ca245b2552042eb96eb6e65838af7fea703af685..9696dfe8125a562ae059628b7e0b44977e770ecf 100644 (file)
@@ -978,8 +978,9 @@ find_typval_in_script(typval_T *dest)
        // legacy script doesn't store variable types
        return NULL;
 
-    // Find the svar_T in sn_var_vals.
-    for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx)
+    // Find the svar_T in sn_var_vals.  Start at the end, in a for loop the
+    // variable was added at the end.
+    for (idx = si->sn_var_vals.ga_len - 1; idx >= 0; --idx)
     {
        svar_T    *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;