patch 9.1.1942: Vim9: Assignment to read-only registers @: and @% is allowed

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>
This commit is contained in:
Doug Kearns
2025-11-30 15:26:22 +00:00
committed by Christian Brabandt
parent 791478b30a
commit e5c5378cd2
4 changed files with 17 additions and 4 deletions

View 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:')

View 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.

View File

@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1942,
/**/
1941,
/**/

View 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;