]> granicus.if.org Git - vim/commitdiff
patch 8.2.1003: Vim9: return type of sort() is too generic v8.2.1003
authorBram Moolenaar <Bram@vim.org>
Thu, 18 Jun 2020 16:45:49 +0000 (18:45 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 18 Jun 2020 16:45:49 +0000 (18:45 +0200)
Problem:    Vim9: return type of sort() is too generic.
Solution:   Get type from the first argument. (closes #6292)

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

index 230962e94da626e2020134d1adad7c793b567aa4..66788837575c8179adac588c9006895a9b29a44d 100644 (file)
@@ -339,6 +339,14 @@ ret_job(int argcount UNUSED, type_T **argtypes UNUSED)
     return &t_job;
 }
 
+    static type_T *
+ret_first_arg(int argcount, type_T **argtypes)
+{
+    if (argcount > 0)
+       return argtypes[0];
+    return &t_void;
+}
+
 static type_T *ret_f_function(int argcount, type_T **argtypes);
 
 /*
@@ -849,7 +857,7 @@ static funcentry_T global_functions[] =
     {"simplify",       1, 1, FEARG_1,    ret_string,   f_simplify},
     {"sin",            1, 1, FEARG_1,    ret_float,    FLOAT_FUNC(f_sin)},
     {"sinh",           1, 1, FEARG_1,    ret_float,    FLOAT_FUNC(f_sinh)},
-    {"sort",           1, 3, FEARG_1,    ret_list_any, f_sort},
+    {"sort",           1, 3, FEARG_1,    ret_first_arg, f_sort},
     {"sound_clear",    0, 0, 0,          ret_void,     SOUND_FUNC(f_sound_clear)},
     {"sound_playevent",        1, 2, FEARG_1,    ret_number,   SOUND_FUNC(f_sound_playevent)},
     {"sound_playfile", 1, 2, FEARG_1,    ret_number,   SOUND_FUNC(f_sound_playfile)},
index 6c661111a0a175416a76b973adff00c8d2f210e5..c0a4d9bd65573ae1d5d12168583304fec42c36cd 100644 (file)
@@ -807,5 +807,10 @@ def Test_call_closure_not_compiled()
   assert_equal('sometext', GetResult(g:Ref))
 enddef
 
+def Test_sort_return_type()
+  let res: list<number>
+  res = [1, 2, 3]->sort()
+enddef
+
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 34bb99bb86a5e88f0cda5fdc68b256df05523a0d..2cdb140cf465a16b64e7bceb7cf4d3c2bb7f84d2 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1003,
 /**/
     1002,
 /**/