changeset 27865:05d222e5246a v8.2.4458

patch 8.2.4458: Vim9: compiling filter() call fails with unknown arguments Commit: https://github.com/vim/vim/commit/6e1a38745f794715dc624399c318f513b54797c4 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 23 19:11:49 2022 +0000 patch 8.2.4458: Vim9: compiling filter() call fails with unknown arguments Problem: Vim9: compiling filter() call fails with funcref that has unknown arguments. Solution: Do not check the arguments if they are unknown at compile time. (closes #9835)
author Bram Moolenaar <Bram@vim.org>
date Wed, 23 Feb 2022 20:15:03 +0100
parents dbc9ba82d6fd
children 8ae06422a149
files src/evalfunc.c src/testdir/test_vim9_builtin.vim src/version.c
diffstat 3 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -552,6 +552,8 @@ check_map_filter_arg2(type_T *type, argc
 	    t_func_exp.tt_member = &t_bool;
 	if (args[0] == NULL)
 	    args[0] = &t_unknown;
+	if (type->tt_argcount == -1)
+	    t_func_exp.tt_argcount = -1;
 
 	where.wt_index = 2;
 	return check_type(&t_func_exp, type, TRUE, where);
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -1340,10 +1340,21 @@ def Test_filter()
   enddef
   assert_equal([1], GetFiltered())
 
+  var lines =<< trim END
+      vim9script
+      def Func(): list<string>
+        var MatchWord: func: bool = (_, v) => true
+        var l = ['xxx']
+        return l->filter(MatchWord)
+      enddef
+      assert_equal(['xxx'], Func())
+  END
+  v9.CheckScriptSuccess(lines)
+
   v9.CheckDefAndScriptFailure(['filter(1.1, "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got float', 'E1251: List, Dictionary, Blob or String required for argument 1'])
   v9.CheckDefAndScriptFailure(['filter([1, 2], 4)'], ['E1256: String or function required for argument 2', 'E1024: Using a Number as a String'])
 
-  var lines =<< trim END
+  lines =<< trim END
     def F(i: number, v: any): string
       return 'bad'
     enddef
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4458,
+/**/
     4457,
 /**/
     4456,