Patch 8.2.1270
Problem: Vim9: not skipping over function type declaration with only a
return type.
Solution: Skip over the return type. (issue #6507)
Files: src/vim9compile.c, src/testdir/test_vim9_func.vim
*** ../vim-8.2.1269/src/vim9compile.c 2020-07-21 20:55:46.869920170 +0200
--- src/vim9compile.c 2020-07-22 19:25:12.153304079 +0200
***************
*** 1881,1906 ****
if (*p == '>')
++p;
}
! else if (*p == '(' && STRNCMP("func", start, 4) == 0)
{
! // handle func(args): type
! ++p;
! while (*p != ')' && *p != NUL)
{
! char_u *sp = p;
! p = skip_type(p);
! if (p == sp)
! return p; // syntax error
! if (*p == ',')
! p = skipwhite(p + 1);
}
! if (*p == ')')
{
! if (p[1] == ':')
! p = skip_type(skipwhite(p + 2));
! else
! p = skipwhite(p + 1);
}
}
--- 1881,1915 ----
if (*p == '>')
++p;
}
! else if ((*p == '(' || (*p == ':' && VIM_ISWHITE(p[1])))
! && STRNCMP("func", start, 4) == 0)
{
! if (*p == '(')
{
! // handle func(args): type
! ++p;
! while (*p != ')' && *p != NUL)
! {
! char_u *sp = p;
! p = skip_type(p);
! if (p == sp)
! return p; // syntax error
! if (*p == ',')
! p = skipwhite(p + 1);
! }
! if (*p == ')')
! {
! if (p[1] == ':')
! p = skip_type(skipwhite(p + 2));
! else
! p = skipwhite(p + 1);
! }
}
! else
{
! // handle func: return_type
! p = skip_type(skipwhite(p + 1));
}
}
*** ../vim-8.2.1269/src/testdir/test_vim9_func.vim 2020-07-19 14:03:05.067941890 +0200
--- src/testdir/test_vim9_func.vim 2020-07-22 19:27:43.936691019 +0200
***************
*** 260,265 ****
--- 260,275 ----
assert_equal(3, g:SomeFunc('abc'))
assert_fails('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
let SomeFunc = function('len')
*** ../vim-8.2.1269/src/version.c 2020-07-22 19:10:59.877072059 +0200
--- src/version.c 2020-07-22 19:29:41.704220673 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1270,
/**/
--
Creating the world with Emacs: M-x let-there-be-light
Creating the world with Vim: :make world
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///