patch 9.1.0665: Locked variable can be changed in a :for loop

Commit: 
https://github.com/vim/vim/commit/6b97d7ad197de0fb38648c91552c4374e39fdf98
Author: zeertzjq <zeert...@outlook.com>
Date:   Thu Aug 8 21:05:57 2024 +0200

    patch 9.1.0665: Locked variable can be changed in a :for loop
    
    Problem:  Locked variable can be changed in a :for loop.
    Solution: Always do a full permission check on the first loop iteration
              where ASSIGN_DECL is not set (zeertzjq).
    
    related: #12470
    fixes: #15450
    closes: #15454
    
    Signed-off-by: zeertzjq <zeert...@outlook.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/evalvars.c b/src/evalvars.c
index 6facbeb13..f18b51637 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -4100,7 +4100,7 @@ set_var_const(
 
            // Modifying a final variable with a List value using the "+="
            // operator is allowed.  For other types, it is not allowed.
-           if (((flags & ASSIGN_FOR_LOOP) == 0
+           if ((((flags & ASSIGN_FOR_LOOP) == 0 || (flags & ASSIGN_DECL) == 0)
                        && ((flags & ASSIGN_COMPOUND_OP) == 0
                            || !type_inplace_modifiable))
                                 ? var_check_permission(di, name) == FAIL
diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim
index a346399eb..1b17108c4 100644
--- a/src/testdir/test_eval_stuff.vim
+++ b/src/testdir/test_eval_stuff.vim
@@ -2,6 +2,7 @@
 
 source view_util.vim
 source shared.vim
+import './vim9.vim' as v9
 
 function s:foo() abort
   try
@@ -126,7 +127,31 @@ func Test_for_invalid()
   call assert_fails("for x in 99", 'E1098:')
   call assert_fails("for x in function('winnr')", 'E1098:')
   call assert_fails("for x in {'a': 9}", 'E1098:')
-  call assert_fails("for v:maxcol in range(1)", 'E46:')
+
+  let lines =<< trim END
+    for v:maxcol in range(5)
+    endfor
+  END
+
+  let save_v_maxcol = v:maxcol
+  call v9.CheckLegacyAndVim9Failure(lines, 'E46:')
+  call assert_equal(save_v_maxcol, v:maxcol)
+
+  let lines =<< trim END
+    for g:constvar in range(5)
+    endfor
+  END
+
+  const g:constvar = 10
+  call v9.CheckLegacyAndVim9Failure(lines, 'E741:')
+  call assert_equal(10, g:constvar)
+  unlet g:constvar
+
+  let g:constvar = 10
+  lockvar 0 g:constvar
+  call v9.CheckLegacyAndVim9Failure(lines, 'E1122:')
+  call assert_equal(10, g:constvar)
+  unlet g:constvar
 
   if 0
     /1/5/2/s/

diff --git a/src/version.c b/src/version.c
index ce5894f89..1b7e42335 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    665,
 /**/
     664,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1sc8bJ-0064un-52%40256bit.org.

Raspunde prin e-mail lui