]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1942: Vim9: Assignment to read-only registers @: and @% is allowed v9.1.1942
authorDoug Kearns <dougkearns@gmail.com>
Sun, 30 Nov 2025 15:26:22 +0000 (15:26 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 30 Nov 2025 15:26:22 +0000 (15:26 +0000)
Problem:  Assignment to read-only registers @: and @% is allowed during
          compilation.
Solution: Abort compilation and emit an E354 error when assigning to
          these registers (Doug Kearns).

Fix the E354 error emitted when attempting to declare @: with :var so
that it references the correct register, @:,  rather than the garbage
string "^@".

closes: #18806

Signed-off-by: Doug Kearns <dougkearns@gmail.com>
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_assign.vim
src/testdir/test_vim9_expr.vim
src/version.c
src/vim9compile.c

index b7b09c972424c85aaeceaba6550d8724a8c2106c..a8c6c01cb3cf9cf7fce10bf8f15e13effefd085e 100644 (file)
@@ -1592,12 +1592,17 @@ def Test_assignment_failure()
   v9.CheckDefFailure(['var $VAR = 5'], 'E1016: Cannot declare an environment variable:')
   v9.CheckScriptFailure(['vim9script', 'var $ENV = "xxx"'], 'E1016:')
 
+  # read-only registers
+  v9.CheckDefAndScriptFailure(['var @. = 5'], ['E354:', 'E1066:'], 1)
+  v9.CheckDefAndScriptFailure(['var @. = 5'], ['E354:', 'E1066:'], 1)
+  v9.CheckDefAndScriptFailure(['var @% = 5'], ['E354:', 'E1066:'], 1)
+  v9.CheckDefAndScriptFailure(['var @: = 5'], ['E354:', 'E1066:'], 1)
   if has('dnd')
-    v9.CheckDefFailure(['var @~ = 5'], 'E1066:')
+    v9.CheckDefAndScriptFailure(['var @~ = 5'], ['E354:', 'E1066:'], 1)
   else
-    v9.CheckDefFailure(['var @~ = 5'], 'E354:')
-    v9.CheckDefFailure(['@~ = 5'], 'E354:')
+    v9.CheckDefAndScriptFailure(['var @~ = 5'], ['E354:', 'E1066:'], 1)
   endif
+
   v9.CheckDefFailure(['var @a = 5'], 'E1066:')
   v9.CheckDefFailure(['var @/ = "x"'], 'E1066:')
   v9.CheckScriptFailure(['vim9script', 'var @a = "abc"'], 'E1066:')
index bbc9e1065321efa36e0876c4f9adea9cc157555d..8e5a53d51cb75ba2287859d0a78ab6f6ffec7da1 100644 (file)
@@ -3352,7 +3352,11 @@ def Test_expr9_register()
   END
   v9.CheckDefAndScriptSuccess(lines)
 
+  # read-only registers
   v9.CheckDefAndScriptFailure(["@. = 'yes'"], 'E354:', 1)
+  v9.CheckDefAndScriptFailure(["@% = 'yes'"], 'E354:', 1)
+  v9.CheckDefAndScriptFailure(["@: = 'yes'"], 'E354:', 1)
+  v9.CheckDefAndScriptFailure(["@~ = 'yes'"], 'E354:', 1)
 enddef
 
 " This is slow when run under valgrind.
index a8bff776af94d34fbe76c91ed5027ffcc71fb190..81e8cf3b7a215b9ef71519f2d9261faa726285a4 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1942,
 /**/
     1941,
 /**/
index cab48bb8ae423623834d844ddb6087d15840fd0d..43f8dcb7fa8e0d328ba6db952df6f3eb6a2c3f78 100644 (file)
@@ -1464,7 +1464,9 @@ vim9_declare_error(char_u *name)
     static int
 valid_dest_reg(int name)
 {
-    if ((name == '@' || valid_yank_reg(name, FALSE)) && name != '.')
+    if (name == '@')
+       name = '"';
+    if (name == '/' || name == '=' || valid_yank_reg(name, TRUE))
        return TRUE;
     emsg_invreg(name);
     return FAIL;