]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def v8.2.2405
authorBram Moolenaar <Bram@vim.org>
Sun, 24 Jan 2021 20:14:20 +0000 (21:14 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 24 Jan 2021 20:14:20 +0000 (21:14 +0100)
Problem:    Vim9: no need to allow white space before "(" for :def.
Solution:   Give an error for stray white space. (issue #7734)

src/testdir/test_vim9_func.vim
src/userfunc.c
src/version.c

index fc1ed2120af19e0950aee9c7861fd9b1a26e37ff..a5855adcbc7eeeb6ba12336a4a9d2320b22ad60d 100644 (file)
@@ -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',
index 92166858230060d73d46d0eb9e8bb4e153fcf224..0f28b028e7e5ddd6d04b02902d9f38ea1589b676 100644 (file)
@@ -3199,6 +3199,12 @@ define_function(exarg_T *eap, char_u *name_arg)
            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)
     {
index 43ad049da51fc1595dbc71a812c9df23cc2dfae9..136448a3523a4bec66180beca9aa7cea1abc5b8f 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2405,
 /**/
     2404,
 /**/