changeset 23426:c3c690c8fcbf v8.2.2256

patch 8.2.2256: Vim9: cannot use function( after line break in :def function Commit: https://github.com/vim/vim/commit/adc8e4464563a2952c10362d396bb4a9f28cd12d Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 31 18:28:18 2020 +0100 patch 8.2.2256: Vim9: cannot use function( after line break in :def function Problem: Vim9: cannot use function( after line break in :def function. Solution: Check for "(" after "function". (closes https://github.com/vim/vim/issues/7581)
author Bram Moolenaar <Bram@vim.org>
date Thu, 31 Dec 2020 18:30:04 +0100
parents a3c77a2e53b6
children 8f2dcc0cfcf6
files src/testdir/test_vim9_func.vim src/userfunc.c src/version.c
diffstat 3 files changed, 29 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -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')
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -2925,6 +2925,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
  * the function name.
@@ -3426,7 +3447,7 @@ define_function(exarg_T *eap, char_u *na
 	    // 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 == '!')
--- 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 */
 /**/
+    2256,
+/**/
     2255,
 /**/
     2254,