]> granicus.if.org Git - vim/commitdiff
patch 8.2.2256: Vim9: cannot use function( after line break in :def function v8.2.2256
authorBram Moolenaar <Bram@vim.org>
Thu, 31 Dec 2020 17:28:18 +0000 (18:28 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 31 Dec 2020 17:28:18 +0000 (18:28 +0100)
Problem:    Vim9: cannot use function( after line break in :def function.
Solution:   Check for "(" after "function". (closes #7581)

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

index bdced0257b60e44b15c00f26ea5f3402d2195d44..d0d4e3bb01f5833728ce9e9690daade16813508a 100644 (file)
@@ -260,6 +260,11 @@ def Test_nested_function()
   CheckScriptSuccess(lines)
 enddef
 
+def Test_not_nested_function()
+  echo printf('%d',
+      function('len')('xxx'))
+enddef
+
 func Test_call_default_args_from_func()
   call MyDefaultArgs()->assert_equal('string')
   call MyDefaultArgs('one')->assert_equal('one')
index a70870baae6cc6f90fc8c438e1eb806075252fc1..bc3dd0e9ae383d735465119db5026ddfc9662ad4 100644 (file)
@@ -2924,6 +2924,27 @@ list_functions(regmatch_T *regmatch)
     }
 }
 
+/*
+ * Check if "*cmd" points to a function command and if so advance "*cmd" and
+ * return TRUE.
+ * Otherwise return FALSE;
+ * Do not consider "function(" to be a command.
+ */
+    static int
+is_function_cmd(char_u **cmd)
+{
+    char_u *p = *cmd;
+
+    if (checkforcmd(&p, "function", 2))
+    {
+       if (*p == '(')
+           return FALSE;
+       *cmd = p;
+       return TRUE;
+    }
+    return FALSE;
+}
+
 /*
  * ":function" also supporting nested ":def".
  * When "name_arg" is not NULL this is a nested function, using "name_arg" for
@@ -3426,7 +3447,7 @@ define_function(exarg_T *eap, char_u *name_arg)
            // Only recognize "def" inside "def", not inside "function",
            // For backwards compatibility, see Test_function_python().
            c = *p;
-           if (checkforcmd(&p, "function", 2)
+           if (is_function_cmd(&p)
                    || (eap->cmdidx == CMD_def && checkforcmd(&p, "def", 3)))
            {
                if (*p == '!')
index 0ef6918bdd8c6ff242f3e32f15776ae9499ef1ca..75813ed363698ff06dedb7add0342e3471e70ee1 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2256,
 /**/
     2255,
 /**/