changeset 24371:2b4883926a24 v8.2.2726

patch 8.2.2726: confusing error message with white space before comma Commit: https://github.com/vim/vim/commit/86cdb8a4bd1abff40b5f80c3c4149b33cbaab990 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 6 19:01:03 2021 +0200 patch 8.2.2726: confusing error message with white space before comma Problem: Confusing error message with white space before comma in the arguments of a function declaration. Solution: Give a specific error message. (closes #2235)
author Bram Moolenaar <Bram@vim.org>
date Tue, 06 Apr 2021 19:15:04 +0200
parents 7ba92a32a607
children 9ca6b66bf46f
files src/testdir/test_vim9_func.vim src/userfunc.c src/version.c
diffstat 3 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -1263,6 +1263,15 @@ def Test_arg_type_wrong()
   CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:')
 enddef
 
+def Test_white_space_before_comma()
+  var lines =<< trim END
+    vim9script
+    def Func(a: number , b: number)
+    enddef
+  END
+  CheckScriptFailure(lines, 'E1068:')
+enddef
+
 def Test_white_space_after_comma()
   var lines =<< trim END
     vim9script
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -307,6 +307,17 @@ get_function_args(
 		emsg(_("E989: Non-default argument follows default argument"));
 		goto err_ret;
 	    }
+
+	    if (VIM_ISWHITE(*p) && *skipwhite(p) == ',')
+	    {
+		// Be tolerant when skipping
+		if (!skip)
+		{
+		    semsg(_(e_no_white_space_allowed_before_str_str), ",", p);
+		    goto err_ret;
+		}
+		p = skipwhite(p);
+	    }
 	    if (*p == ',')
 	    {
 		++p;
--- 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 */
 /**/
+    2726,
+/**/
     2725,
 /**/
     2724,