]> granicus.if.org Git - vim/commitdiff
patch 8.2.4459: Vim9: compiling sort() call fails with unknown arguments v8.2.4459
authorBram Moolenaar <Bram@vim.org>
Wed, 23 Feb 2022 21:03:32 +0000 (21:03 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 23 Feb 2022 21:03:32 +0000 (21:03 +0000)
Problem:    Vim9: compiling sort() call fails with a 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 e8ed4bab045ea2504a054dea394ffc3d18704970..1b93200367952fb7c237c2cbb86f19cf1d4e0866 100644 (file)
@@ -624,6 +624,8 @@ arg_sort_how(type_T *type, type_T *decl_type UNUSED, argcontext_T *context)
            where_T where = WHERE_INIT;
 
            args[1] = args[0];
+           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 dfec991f8d12eb6555e96a6faef19d7f6ae39253..7577aecd2a18fd3448f7becd4053dd89de57a86d 100644 (file)
@@ -3812,6 +3812,17 @@ def Test_sort_argument()
       sort([1, 2, 3], (a: any, b: any) => 1)
   END
   v9.CheckDefAndScriptSuccess(lines)
+
+  lines =<< trim END
+      vim9script
+      def SortedList(): list<number>
+        var Lambda: func: number = (a, b): number => a - b
+        var l = [3, 2, 1]
+        return l->sort(Lambda)
+      enddef
+      SortedList()->assert_equal([1, 2, 3])
+  END
+  v9.CheckScriptSuccess(lines)
 enddef
 
 def Test_sort_compare_func_fails()
index 800925df98408ddfa54c1fef72191588847602bb..f8fb3139c9d170874a86ba8ace06851e87aaa065 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4459,
 /**/
     4458,
 /**/