summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-09-21 21:48:21 +0200
committerBram Moolenaar <Bram@vim.org>2020-09-21 21:48:21 +0200
commitdbd759309b4b6abea96b18d61770e100cf4264b5 (patch)
tree712bab74dbb71b8b3e33ad39a30931718a723968
parent7f9c9c51a3680f120e1c3f2bb7239c9fa115b27f (diff)
downloadvim-git-dbd759309b4b6abea96b18d61770e100cf4264b5.tar.gz
patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type functionv8.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)
-rw-r--r--src/testdir/test_vim9_expr.vim12
-rw-r--r--src/version.c2
-rw-r--r--src/vim9type.c6
3 files changed, 19 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 411ed7017..7900dd794 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -1687,6 +1687,18 @@ def Test_expr7_lambda_vim9script()
->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()
diff --git a/src/version.c b/src/version.c
index 29199d2cd..7cc9e7beb 100644
--- 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 */
/**/
+ 1722,
+/**/
1721,
/**/
1720,
diff --git a/src/vim9type.c b/src/vim9type.c
index a7ffd32ed..c7e3dde32 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -463,7 +463,11 @@ check_type(type_T *expected, type_T *actual, int give_msg, int argidx)
&& !(expected->tt_type == VAR_ANY && actual->tt_type != VAR_VOID))
{
- if (expected->tt_type != actual->tt_type)
+ // 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))