• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision712bc35842aa0753b5dc802785977b4743ead9c9 (tree)
Zeit2020-09-22 05:00:03
AutorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function

Commit: https://github.com/vim/vim/commit/dbd759309b4b6abea96b18d61770e100cf4264b5
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 21 21:48:21 2020 +0200

patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
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)

Ändern Zusammenfassung

Diff

diff -r a395dbac89f7 -r 712bc35842aa src/testdir/test_vim9_expr.vim
--- a/src/testdir/test_vim9_expr.vim Mon Sep 21 21:45:04 2020 +0200
+++ b/src/testdir/test_vim9_expr.vim Mon Sep 21 22:00:03 2020 +0200
@@ -1687,6 +1687,18 @@
16871687 ->map({_, v -> synIDattr(v, 'name')})->len()})
16881688 END
16891689 CheckScriptSuccess(lines)
1690+
1691+ # check if assign a lambda to a variable which type is func or any.
1692+ lines =<< trim END
1693+ vim9script
1694+ let FuncRef = {->123}
1695+ assert_equal(123, FuncRef())
1696+ let FuncRef_Func: func = {->123}
1697+ assert_equal(123, FuncRef_Func())
1698+ let FuncRef_Any: any = {->123}
1699+ assert_equal(123, FuncRef_Any())
1700+ END
1701+ CheckScriptSuccess(lines)
16901702 enddef
16911703
16921704 def Test_epxr7_funcref()
diff -r a395dbac89f7 -r 712bc35842aa src/version.c
--- a/src/version.c Mon Sep 21 21:45:04 2020 +0200
+++ b/src/version.c Mon Sep 21 22:00:03 2020 +0200
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 1722,
755+/**/
754756 1721,
755757 /**/
756758 1720,
diff -r a395dbac89f7 -r 712bc35842aa src/vim9type.c
--- a/src/vim9type.c Mon Sep 21 21:45:04 2020 +0200
+++ b/src/vim9type.c Mon Sep 21 22:00:03 2020 +0200
@@ -463,7 +463,11 @@
463463 && !(expected->tt_type == VAR_ANY && actual->tt_type != VAR_VOID))
464464
465465 {
466- if (expected->tt_type != actual->tt_type)
466+ // tt_type should match, except that a "partial" can be assigned to a
467+ // variable with type "func".
468+ if (!(expected->tt_type == actual->tt_type
469+ || (expected->tt_type == VAR_FUNC
470+ && actual->tt_type == VAR_PARTIAL)))
467471 {
468472 if (expected->tt_type == VAR_BOOL
469473 && (actual->tt_flags & TTFLAG_BOOL_OK))
Show on old repository browser