diff src/evalvars.c @ 21447:369cde0d5771 v8.2.1274

patch 8.2.1274: Vim9: no error for missing white space at script level Commit: https://github.com/vim/vim/commit/63be3d4ba01d565e645d8bf7f4dc900fc9011534 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 23 13:11:37 2020 +0200 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)
author Bram Moolenaar <Bram@vim.org>
date Thu, 23 Jul 2020 13:15:07 +0200
parents 2c40e60017a8
children 4dfd00f481fb
line wrap: on
line diff
--- 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);
 	}
     }