changeset 23727:7d0959080545 v8.2.2405

patch 8.2.2405: Vim9: no need to allow white space before "(" for :def Commit: https://github.com/vim/vim/commit/4efd9948291801bffebf36b4a9910d08ff981987 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 24 21:14:20 2021 +0100 patch 8.2.2405: Vim9: no need to allow white space before "(" for :def Problem: Vim9: no need to allow white space before "(" for :def. Solution: Give an error for stray white space. (issue https://github.com/vim/vim/issues/7734)
author Bram Moolenaar <Bram@vim.org>
date Sun, 24 Jan 2021 21:15:03 +0100
parents d0bacfdcaa82
children 03ab987c442c
files src/testdir/test_vim9_func.vim src/userfunc.c src/version.c
diffstat 3 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -116,6 +116,38 @@ def Test_missing_endfunc_enddef()
   CheckScriptFailure(lines, 'E126:', 2)
 enddef
 
+def Test_white_space_before_paren()
+  var lines =<< trim END
+    vim9script
+    def Test ()
+      echo 'test'
+    enddef
+  END
+  CheckScriptFailure(lines, 'E1068:', 2)
+
+  lines =<< trim END
+    vim9script
+    func Test ()
+      echo 'test'
+    endfunc
+  END
+  CheckScriptFailure(lines, 'E1068:', 2)
+
+  lines =<< trim END
+    def Test ()
+      echo 'test'
+    enddef
+  END
+  CheckScriptFailure(lines, 'E1068:', 1)
+
+  lines =<< trim END
+    func Test ()
+      echo 'test'
+    endfunc
+  END
+  CheckScriptSuccess(lines)
+enddef
+
 def Test_enddef_dict_key()
   var d = {
     enddef: 'x',
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -3199,6 +3199,12 @@ define_function(exarg_T *eap, char_u *na
 	    p = vim_strchr(p, '(');
     }
 
+    if ((vim9script || eap->cmdidx == CMD_def) && VIM_ISWHITE(p[-1]))
+    {
+	semsg(_(e_no_white_space_allowed_before_str), "(");
+	goto ret_free;
+    }
+
     // In Vim9 script only global functions can be redefined.
     if (vim9script && eap->forceit && !is_global)
     {
--- 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 */
 /**/
+    2405,
+/**/
     2404,
 /**/
     2403,