0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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 #7581)
This commit is contained in:
Bram Moolenaar
2020-12-31 18:28:18 +01:00
parent 1779ff4842
commit adc8e44645
3 changed files with 29 additions and 1 deletions

View File

@@ -260,6 +260,11 @@ def Test_nested_function()
CheckScriptSuccess(lines) CheckScriptSuccess(lines)
enddef enddef
def Test_not_nested_function()
echo printf('%d',
function('len')('xxx'))
enddef
func Test_call_default_args_from_func() func Test_call_default_args_from_func()
call MyDefaultArgs()->assert_equal('string') call MyDefaultArgs()->assert_equal('string')
call MyDefaultArgs('one')->assert_equal('one') call MyDefaultArgs('one')->assert_equal('one')

View 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". * ":function" also supporting nested ":def".
* When "name_arg" is not NULL this is a nested function, using "name_arg" for * 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", // Only recognize "def" inside "def", not inside "function",
// For backwards compatibility, see Test_function_python(). // For backwards compatibility, see Test_function_python().
c = *p; c = *p;
if (checkforcmd(&p, "function", 2) if (is_function_cmd(&p)
|| (eap->cmdidx == CMD_def && checkforcmd(&p, "def", 3))) || (eap->cmdidx == CMD_def && checkforcmd(&p, "def", 3)))
{ {
if (*p == '!') if (*p == '!')

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2256,
/**/ /**/
2255, 2255,
/**/ /**/