changeset 23446:b1dbbc81a011 v8.2.2266

patch 8.2.2266: Vim9: it can be hard to see where white space is missing Commit: https://github.com/vim/vim/commit/e7a73e07625b64a40671a0007ad38a34cbe9d1ee Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 1 19:17:55 2021 +0100 patch 8.2.2266: Vim9: it can be hard to see where white space is missing Problem: Vim9: it can be hard to see where white space is missing. Solution: Mention the text where the error was seen. (closes https://github.com/vim/vim/issues/7580)
author Bram Moolenaar <Bram@vim.org>
date Fri, 01 Jan 2021 19:30:04 +0100
parents 311caf397f9b
children 15d05ad7a3a5
files src/errors.h src/eval.c src/evalvars.c src/testdir/test_vim9_expr.vim src/userfunc.c src/version.c src/vim9compile.c
diffstat 7 files changed, 35 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/errors.h
+++ b/src/errors.h
@@ -41,8 +41,8 @@ EXTERN char e_syntax_error_at_str[]
 	INIT(= N_("E1002: Syntax error at %s"));
 EXTERN char e_missing_return_value[]
 	INIT(= N_("E1003: Missing return value"));
-EXTERN char e_white_space_required_before_and_after_str[]
-	INIT(= N_("E1004: White space required before and after '%s'"));
+EXTERN char e_white_space_required_before_and_after_str_at_str[]
+	INIT(= N_("E1004: White space required before and after '%s' at \"%s\""));
 EXTERN char e_too_many_argument_types[]
 	INIT(= N_("E1005: Too many argument types"));
 EXTERN char e_str_is_used_as_argument[]
--- a/src/eval.c
+++ b/src/eval.c
@@ -3778,7 +3778,8 @@ eval_index(
 	    return FAIL;
 	else if (vim9 && **arg == ':')
 	{
-	    semsg(_(e_white_space_required_before_and_after_str), ":");
+	    semsg(_(e_white_space_required_before_and_after_str_at_str),
+								    ":", *arg);
 	    clear_tv(&var1);
 	    return FAIL;
 	}
@@ -3799,7 +3800,8 @@ eval_index(
 	    ++*arg;
 	    if (vim9 && !IS_WHITE_OR_NUL(**arg) && **arg != ']')
 	    {
-		semsg(_(e_white_space_required_before_and_after_str), ":");
+		semsg(_(e_white_space_required_before_and_after_str_at_str),
+								":", *arg - 1);
 		if (!empty1)
 		    clear_tv(&var1);
 		return FAIL;
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -863,7 +863,8 @@ ex_let(exarg_T *eap)
 						   || !IS_WHITE_OR_NUL(*expr)))
 	    {
 		vim_strncpy(op, expr - len, len);
-		semsg(_(e_white_space_required_before_and_after_str), op);
+		semsg(_(e_white_space_required_before_and_after_str_at_str),
+								   op, argend);
 		i = FAIL;
 	    }
 
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -108,7 +108,7 @@ def Test_expr1_trinary_vimscript()
       vim9script
       var name = v:true?1:2
   END
-  CheckScriptFailure(lines, 'E1004:', 2)
+  CheckScriptFailure(lines, 'E1004: White space required before and after ''?'' at "?1:2"', 2)
   lines =<< trim END
       vim9script
       var name = v:true? 1 : 2
@@ -123,7 +123,7 @@ def Test_expr1_trinary_vimscript()
       vim9script
       var name = v:true ? 1: 2
   END
-  CheckScriptFailure(lines, 'E1004:', 2)
+  CheckScriptFailure(lines, 'E1004: White space required before and after '':'' at ": 2"', 2)
   lines =<< trim END
       vim9script
       var name = v:true ? 1 :2
@@ -333,7 +333,7 @@ def Test_expr2_vimscript()
       vim9script
       var name = v:true||v:true
   END
-  CheckScriptFailure(lines, 'E1004:', 2)
+  CheckScriptFailure(lines, 'E1004: White space required before and after ''||'' at "||v:true"', 2)
   lines =<< trim END
       vim9script
       var name = v:true ||v:true
@@ -454,7 +454,7 @@ def Test_expr3_vimscript()
       vim9script
       var name = v:true &&v:true
   END
-  CheckScriptFailure(lines, 'E1004:', 2)
+  CheckScriptFailure(lines, 'E1004: White space required before and after ''&&'' at "&&v:true"', 2)
   lines =<< trim END
       vim9script
       var name = v:true&& v:true
@@ -920,7 +920,7 @@ def Test_expr4_vim9script()
     vim9script
     echo 2>3
   END
-  CheckScriptFailure(lines, 'E1004:', 2)
+  CheckScriptFailure(lines, 'E1004: White space required before and after ''>'' at ">3"', 2)
   lines =<< trim END
     vim9script
     echo 2 >3
@@ -940,7 +940,7 @@ def Test_expr4_vim9script()
     vim9script
     echo 2 !=3
   END
-  CheckScriptFailure(lines, 'E1004:', 2)
+  CheckScriptFailure(lines, 'E1004: White space required before and after ''!'' at "!=3"', 2)
   lines =<< trim END
     vim9script
     echo 2!= 3
@@ -1192,7 +1192,7 @@ def Test_expr5_vim9script()
       vim9script
       echo 'a'..'b'
   END
-  CheckScriptFailure(lines, 'E1004:', 2)
+  CheckScriptFailure(lines, 'E1004: White space required before and after ''..'' at "..''b''"', 2)
   lines =<< trim END
       vim9script
       echo 'a' ..'b'
@@ -1729,7 +1729,8 @@ def Test_expr7_list()
       var a = 1
       var b = 2
   END
-  CheckDefAndScriptFailure(lines + ['echo numbers[1:b]'], 'E1004:', 4)
+  CheckDefAndScriptFailure(lines + ['echo numbers[1:b]'],
+      'E1004: White space required before and after '':'' at ":b]"', 4)
   CheckDefAndScriptFailure(lines + ['echo numbers[1: b]'], 'E1004:', 4)
   CheckDefAndScriptFailure(lines + ['echo numbers[a :b]'], 'E1004:', 4)
 enddef
@@ -1876,7 +1877,7 @@ def Test_expr7_lambda()
   CheckDefAndScriptSuccess(lines)
 
   CheckDefFailure(["var Ref = (a)=>a + 1"], 'E1004:')
-  CheckDefFailure(["var Ref = (a)=> a + 1"], 'E1004:')
+  CheckDefFailure(["var Ref = (a)=> a + 1"], 'E1004: White space required before and after ''=>'' at "=> a + 1"')
   CheckDefFailure(["var Ref = (a) =>a + 1"], 'E1004:')
 
   CheckDefFailure(["filter([1, 2], (k,v) => 1)"], 'E1069:', 1)
@@ -1976,7 +1977,8 @@ def Test_expr7_new_lambda()
 
   CheckDefAndScriptFailure(["var Ref = (a)=>a + 1"], 'E1004:')
   CheckDefAndScriptFailure(["var Ref = (a)=> a + 1"], 'E1004:')
-  CheckDefAndScriptFailure(["var Ref = (a) =>a + 1"], 'E1004:')
+  CheckDefAndScriptFailure(["var Ref = (a) =>a + 1"],
+      'E1004: White space required before and after ''=>'' at " =>a + 1"')
 
   CheckDefFailure(["var Ref: func(number): number = (a: number): string => 'x'"], 'E1012:')
   CheckDefFailure(["var Ref: func(number): string = (a: number): string => 99"], 'E1012:')
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -501,8 +501,8 @@ skip_arrow(
 		|| !IS_WHITE_OR_NUL(s[1])))
     {
 	*white_error = TRUE;
-	semsg(_(e_white_space_required_before_and_after_str),
-						    equal_arrow ? "=>" : "->");
+	semsg(_(e_white_space_required_before_and_after_str_at_str),
+					       equal_arrow ? "=>" : "->", bef);
 	return NULL;
     }
     return skipwhite(s + 1);
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2266,
+/**/
     2265,
 /**/
     2264,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3656,7 +3656,8 @@ compile_subscript(
 		    return FAIL;
 		if (**arg == ':')
 		{
-		    semsg(_(e_white_space_required_before_and_after_str), ":");
+		    semsg(_(e_white_space_required_before_and_after_str_at_str),
+								    ":", *arg);
 		    return FAIL;
 		}
 		if (may_get_next_line_error(p, arg, cctx) == FAIL)
@@ -3669,7 +3670,8 @@ compile_subscript(
 		++*arg;
 		if (!IS_WHITE_OR_NUL(**arg) && **arg != ']')
 		{
-		    semsg(_(e_white_space_required_before_and_after_str), ":");
+		    semsg(_(e_white_space_required_before_and_after_str_at_str),
+								    ":", *arg);
 		    return FAIL;
 		}
 		*arg = skipwhite(*arg);
@@ -4067,7 +4069,7 @@ error_white_both(char_u *op, int len)
     char_u	buf[10];
 
     vim_strncpy(buf, op, len);
-    semsg(_(e_white_space_required_before_and_after_str), buf);
+    semsg(_(e_white_space_required_before_and_after_str_at_str), buf, op);
 }
 
 /*
@@ -4434,7 +4436,8 @@ compile_and_or(
 
 	    if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[2]))
 	    {
-		semsg(_(e_white_space_required_before_and_after_str), op);
+		semsg(_(e_white_space_required_before_and_after_str_at_str),
+								     op, *arg);
 		return FAIL;
 	    }
 
@@ -4608,8 +4611,8 @@ compile_expr1(char_u **arg, cctx_T *cctx
 
 	if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1 + op_falsy]))
 	{
-	    semsg(_(e_white_space_required_before_and_after_str),
-							op_falsy ? "??" : "?");
+	    semsg(_(e_white_space_required_before_and_after_str_at_str),
+						  op_falsy ? "??" : "?", *arg);
 	    return FAIL;
 	}
 
@@ -4695,7 +4698,8 @@ compile_expr1(char_u **arg, cctx_T *cctx
 
 	    if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1]))
 	    {
-		semsg(_(e_white_space_required_before_and_after_str), ":");
+		semsg(_(e_white_space_required_before_and_after_str_at_str),
+								       ":", p);
 		return FAIL;
 	    }