]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4458: Vim9: compiling filter() call fails with unknown arguments v8.2.4458
authorBram Moolenaar <Bram@vim.org>
Wed, 23 Feb 2022 19:11:49 +0000 (19:11 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 23 Feb 2022 19:11:49 +0000 (19:11 +0000)
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)

src/evalfunc.c
src/testdir/test_vim9_builtin.vim
src/version.c

index eb42269cfa9a7aafc301035717baa293a37d543a..e8ed4bab045ea2504a054dea394ffc3d18704970 100644 (file)
@@ -552,6 +552,8 @@ check_map_filter_arg2(type_T *type, argcontext_T *context, int is_map)
            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);
index 7366b8c3f71b7522cafdaa6ab1a718df9b855e90..dfec991f8d12eb6555e96a6faef19d7f6ae39253 100644 (file)
@@ -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
index 85af241730ed8e21f2743f9060c5641be2ca4c7b..800925df98408ddfa54c1fef72191588847602bb 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4458,
 /**/
     4457,
 /**/