From 63be3d4ba01d565e645d8bf7f4dc900fc9011534 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 23 Jul 2020 13:11:37 +0200 Subject: 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) --- src/evalvars.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/evalvars.c') diff --git a/src/evalvars.c b/src/evalvars.c index e2469b0e82..564c65b8aa 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -698,12 +698,13 @@ ex_let(exarg_T *eap) int i; int var_count = 0; int semicolon = 0; - char_u op[2]; + char_u op[4]; char_u *argend; int first = TRUE; int concat; int has_assign; int flags = eap->cmdidx == CMD_const ? LET_IS_CONST : 0; + int vim9script = in_vim9script(); // detect Vim9 assignment without ":let" or ":const" if (eap->arg == eap->cmd) @@ -725,11 +726,11 @@ ex_let(exarg_T *eap) // ":let" without "=": list variables if (*arg == '[') emsg(_(e_invarg)); - else if (expr[0] == '.') - emsg(_("E985: .= is not supported with script version 2")); + else if (expr[0] == '.' && expr[1] == '=') + emsg(_("E985: .= is not supported with script version >= 2")); else if (!ends_excmd2(eap->cmd, arg)) { - if (in_vim9script()) + if (vim9script) { // Vim9 declaration ":let var: type" arg = vim9_declare_scriptvar(eap, arg); @@ -775,6 +776,7 @@ ex_let(exarg_T *eap) else { evalarg_T evalarg; + int len = 1; rettv.v_type = VAR_UNKNOWN; i = FAIL; @@ -787,13 +789,25 @@ ex_let(exarg_T *eap) if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL) { op[0] = *expr; // +=, -=, *=, /=, %= or .= + ++len; if (expr[0] == '.' && expr[1] == '.') // ..= + { ++expr; + ++len; + } } - expr = skipwhite(expr + 2); + expr += 2; } 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) ++emsg_skip; @@ -817,7 +831,7 @@ ex_let(exarg_T *eap) else if (i != FAIL) { (void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count, - flags, op); + flags, op); clear_tv(&rettv); } } -- cgit v1.2.3