0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.1274: Vim9: no error for missing white space at script level

Problem:    Vim9: no error for missing white space in assignment at script
            level.
Solution:   Check for white space. (closes #6495)
This commit is contained in:
Bram Moolenaar
2020-07-23 13:11:37 +02:00
parent c69950ac17
commit 63be3d4ba0
5 changed files with 36 additions and 10 deletions

View File

@@ -4996,7 +4996,8 @@ find_name_end(
for (p = arg; *p != NUL for (p = arg; *p != NUL
&& (eval_isnamec(*p) && (eval_isnamec(*p)
|| (*p == '{' && !vim9script) || (*p == '{' && !vim9script)
|| ((flags & FNE_INCL_BR) && (*p == '[' || *p == '.')) || ((flags & FNE_INCL_BR) && (*p == '['
|| (*p == '.' && eval_isnamec1(p[1]))))
|| mb_nest != 0 || mb_nest != 0
|| br_nest != 0); MB_PTR_ADV(p)) || br_nest != 0); MB_PTR_ADV(p))
{ {

View File

@@ -698,12 +698,13 @@ ex_let(exarg_T *eap)
int i; int i;
int var_count = 0; int var_count = 0;
int semicolon = 0; int semicolon = 0;
char_u op[2]; char_u op[4];
char_u *argend; char_u *argend;
int first = TRUE; int first = TRUE;
int concat; int concat;
int has_assign; int has_assign;
int flags = eap->cmdidx == CMD_const ? LET_IS_CONST : 0; int flags = eap->cmdidx == CMD_const ? LET_IS_CONST : 0;
int vim9script = in_vim9script();
// detect Vim9 assignment without ":let" or ":const" // detect Vim9 assignment without ":let" or ":const"
if (eap->arg == eap->cmd) if (eap->arg == eap->cmd)
@@ -725,11 +726,11 @@ ex_let(exarg_T *eap)
// ":let" without "=": list variables // ":let" without "=": list variables
if (*arg == '[') if (*arg == '[')
emsg(_(e_invarg)); emsg(_(e_invarg));
else if (expr[0] == '.') else if (expr[0] == '.' && expr[1] == '=')
emsg(_("E985: .= is not supported with script version 2")); emsg(_("E985: .= is not supported with script version >= 2"));
else if (!ends_excmd2(eap->cmd, arg)) else if (!ends_excmd2(eap->cmd, arg))
{ {
if (in_vim9script()) if (vim9script)
{ {
// Vim9 declaration ":let var: type" // Vim9 declaration ":let var: type"
arg = vim9_declare_scriptvar(eap, arg); arg = vim9_declare_scriptvar(eap, arg);
@@ -775,6 +776,7 @@ ex_let(exarg_T *eap)
else else
{ {
evalarg_T evalarg; evalarg_T evalarg;
int len = 1;
rettv.v_type = VAR_UNKNOWN; rettv.v_type = VAR_UNKNOWN;
i = FAIL; i = FAIL;
@@ -787,13 +789,25 @@ ex_let(exarg_T *eap)
if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL) if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL)
{ {
op[0] = *expr; // +=, -=, *=, /=, %= or .= op[0] = *expr; // +=, -=, *=, /=, %= or .=
++len;
if (expr[0] == '.' && expr[1] == '.') // ..= if (expr[0] == '.' && expr[1] == '.') // ..=
{
++expr; ++expr;
++len;
}
} }
expr = skipwhite(expr + 2); expr += 2;
} }
else else
expr = skipwhite(expr + 1); ++expr;
if (vim9script && (!VIM_ISWHITE(*argend) || !VIM_ISWHITE(*expr)))
{
vim_strncpy(op, expr - len, len);
semsg(_(e_white_both), op);
i = FAIL;
}
expr = skipwhite(expr);
if (eap->skip) if (eap->skip)
++emsg_skip; ++emsg_skip;
@@ -817,7 +831,7 @@ ex_let(exarg_T *eap)
else if (i != FAIL) else if (i != FAIL)
{ {
(void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count, (void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count,
flags, op); flags, op);
clear_tv(&rettv); clear_tv(&rettv);
} }
} }

View File

@@ -293,12 +293,12 @@ func Test_let_errors()
let s = "var" let s = "var"
let var = 1 let var = 1
call assert_fails('let var += [1,2]', 'E734:') call assert_fails('let var += [1,2]', 'E734:')
call assert_fails('let {s}.1 = 2', 'E18:') call assert_fails('let {s}.1 = 2', 'E15:')
call assert_fails('let a[1] = 5', 'E121:') call assert_fails('let a[1] = 5', 'E121:')
let l = [[1,2]] let l = [[1,2]]
call assert_fails('let l[:][0] = [5]', 'E708:') call assert_fails('let l[:][0] = [5]', 'E708:')
let d = {'k' : 4} let d = {'k' : 4}
call assert_fails('let d.# = 5', 'E713:') call assert_fails('let d.# = 5', 'E488:')
call assert_fails('let d.m += 5', 'E734:') call assert_fails('let d.m += 5', 'E734:')
call assert_fails('let m = d[{]', 'E15:') call assert_fails('let m = d[{]', 'E15:')
let l = [1, 2] let l = [1, 2]

View File

@@ -318,6 +318,15 @@ def Test_assignment_failure()
call CheckDefFailure(['let var =234'], 'E1004:') call CheckDefFailure(['let var =234'], 'E1004:')
call CheckDefFailure(['let var= 234'], 'E1004:') call CheckDefFailure(['let var= 234'], 'E1004:')
call CheckScriptFailure(['vim9script', 'let var=234'], 'E1004:')
call CheckScriptFailure(['vim9script', 'let var=234'], "before and after '='")
call CheckScriptFailure(['vim9script', 'let var =234'], 'E1004:')
call CheckScriptFailure(['vim9script', 'let var= 234'], 'E1004:')
call CheckScriptFailure(['vim9script', 'let var = 234', 'var+=234'], 'E1004:')
call CheckScriptFailure(['vim9script', 'let var = 234', 'var+=234'], "before and after '+='")
call CheckScriptFailure(['vim9script', 'let var = "x"', 'var..="y"'], 'E1004:')
call CheckScriptFailure(['vim9script', 'let var = "x"', 'var..="y"'], "before and after '..='")
call CheckDefFailure(['let true = 1'], 'E1034:') call CheckDefFailure(['let true = 1'], 'E1034:')
call CheckDefFailure(['let false = 1'], 'E1034:') call CheckDefFailure(['let false = 1'], 'E1034:')

View File

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