1
0
forked from aniani/vim

patch 8.2.1270: Vim9: not skipping over function type declaration

Problem:    Vim9: not skipping over function type declaration with only a
            return type.
Solution:   Skip over the return type. (issue #6507)
This commit is contained in:
Bram Moolenaar 2020-07-22 19:30:06 +02:00
parent 054f14bbe5
commit 2f1980f7b7
3 changed files with 36 additions and 15 deletions

View File

@ -260,6 +260,16 @@ def Test_call_funcref()
assert_equal(3, g:SomeFunc('abc')) assert_equal(3, g:SomeFunc('abc'))
assert_fails('NotAFunc()', 'E117:') assert_fails('NotAFunc()', 'E117:')
assert_fails('g:NotAFunc()', 'E117:') assert_fails('g:NotAFunc()', 'E117:')
let lines =<< trim END
vim9script
def RetNumber(): number
return 123
enddef
let Funcref: func: number = function('RetNumber')
assert_equal(123, Funcref())
END
CheckScriptSuccess(lines)
enddef enddef
let SomeFunc = function('len') let SomeFunc = function('len')

View File

@ -754,6 +754,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 */
/**/
1270,
/**/ /**/
1269, 1269,
/**/ /**/

View File

@ -1881,7 +1881,10 @@ skip_type(char_u *start)
if (*p == '>') if (*p == '>')
++p; ++p;
} }
else if (*p == '(' && STRNCMP("func", start, 4) == 0) else if ((*p == '(' || (*p == ':' && VIM_ISWHITE(p[1])))
&& STRNCMP("func", start, 4) == 0)
{
if (*p == '(')
{ {
// handle func(args): type // handle func(args): type
++p; ++p;
@ -1903,6 +1906,12 @@ skip_type(char_u *start)
p = skipwhite(p + 1); p = skipwhite(p + 1);
} }
} }
else
{
// handle func: return_type
p = skip_type(skipwhite(p + 1));
}
}
return p; return p;
} }