0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.1502: Vim9: can use += with a :let command at script level

Problem:    Vim9: can use += with a :let command at script level.
Solution:   Give an error.
This commit is contained in:
Bram Moolenaar 2020-08-21 21:32:50 +02:00
parent 3fc71285d5
commit 122616d9c1
4 changed files with 13 additions and 4 deletions

View File

@ -786,7 +786,13 @@ ex_let(exarg_T *eap)
op[1] = NUL;
if (*expr != '=')
{
if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL)
if (vim9script && (flags & LET_NO_COMMAND) == 0)
{
// +=, /=, etc. require an existing variable
semsg(_(e_cannot_use_operator_on_new_variable), eap->arg);
i = FAIL;
}
else if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL)
{
op[0] = *expr; // +=, -=, *=, /=, %= or .=
++len;

View File

@ -1682,8 +1682,6 @@ def Test_expr7_dict()
call CheckDefFailure(["let x = {xxx: 8}"], 'E1001:', 1)
call CheckDefFailure(["let x = #{a: 1, a: 2}"], 'E721:', 1)
call CheckDefFailure(["let x = #"], 'E1015:', 1)
call CheckDefFailure(["let x += 1"], 'E1020:', 1)
call CheckDefFailure(["let x = x + 1"], 'E1001:', 1)
call CheckDefExecFailure(["let x = g:anint.member"], 'E715:', 1)
call CheckDefExecFailure(["let x = g:dict_empty.member"], 'E716:', 1)

View File

@ -569,7 +569,10 @@ def Test_assignment_failure()
call CheckDefFailure(['let t:var = 5'], 'E1016: Cannot declare a tab variable:')
call CheckDefFailure(['let anr = 4', 'anr ..= "text"'], 'E1019:')
call CheckDefFailure(['let xnr += 4'], 'E1020:')
call CheckDefFailure(['let xnr += 4'], 'E1020:', 1)
call CheckScriptFailure(['vim9script', 'let xnr += 4'], 'E1020:')
call CheckDefFailure(["let xnr = xnr + 1"], 'E1001:', 1)
call CheckScriptFailure(['vim9script', 'let xnr = xnr + 4'], 'E121:')
call CheckScriptFailure(['vim9script', 'def Func()', 'let dummy = s:notfound', 'enddef', 'defcompile'], 'E1108:')

View File

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