Patch 8.2.1722
Problem: Vim9: cannot assign a lambda to a variable of type function.
Solution: Allow for assigning a partial to a variable of type function.
(Naruhiko Nishino, closes #6996)
Files: src/vim9type.c, src/testdir/test_vim9_expr.vim
*** ../vim-8.2.1721/src/vim9type.c 2020-09-19 14:12:29.178954287 +0200
--- src/vim9type.c 2020-09-21 21:45:41.482684323 +0200
***************
*** 463,469 ****
&& !(expected->tt_type == VAR_ANY && actual->tt_type != VAR_VOID))
{
! if (expected->tt_type != actual->tt_type)
{
if (expected->tt_type == VAR_BOOL
&& (actual->tt_flags & TTFLAG_BOOL_OK))
--- 463,473 ----
&& !(expected->tt_type == VAR_ANY && actual->tt_type != VAR_VOID))
{
! // tt_type should match, except that a "partial" can be assigned to a
! // variable with type "func".
! if (!(expected->tt_type == actual->tt_type
! || (expected->tt_type == VAR_FUNC
! && actual->tt_type == VAR_PARTIAL)))
{
if (expected->tt_type == VAR_BOOL
&& (actual->tt_flags & TTFLAG_BOOL_OK))
*** ../vim-8.2.1721/src/testdir/test_vim9_expr.vim 2020-09-20 22:43:48.209496857 +0200
--- src/testdir/test_vim9_expr.vim 2020-09-21 21:40:11.328274446 +0200
***************
*** 1687,1692 ****
--- 1687,1704 ----
->map({_, v -> synIDattr(v, 'name')})->len()})
END
CheckScriptSuccess(lines)
+
+ # check if assign a lambda to a variable which type is func or any.
+ lines =<< trim END
+ vim9script
+ let FuncRef = {->123}
+ assert_equal(123, FuncRef())
+ let FuncRef_Func: func = {->123}
+ assert_equal(123, FuncRef_Func())
+ let FuncRef_Any: any = {->123}
+ assert_equal(123, FuncRef_Any())
+ END
+ CheckScriptSuccess(lines)
enddef
def Test_epxr7_funcref()
*** ../vim-8.2.1721/src/version.c 2020-09-21 21:29:51.215279350 +0200
--- src/version.c 2020-09-21 21:47:58.805813888 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 1722,
/**/
--
ARTHUR: You are indeed brave Sir knight, but the fight is mine.
BLACK KNIGHT: Had enough?
ARTHUR: You stupid bastard. You havn't got any arms left.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// 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 ///