]> granicus.if.org Git - vim/commitdiff
patch 8.2.1701: Vim9: sort("i") does not work v8.2.1701
authorBram Moolenaar <Bram@vim.org>
Wed, 16 Sep 2020 21:23:36 +0000 (23:23 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 16 Sep 2020 21:23:36 +0000 (23:23 +0200)
Problem:    Vim9: sort("i") does not work.
Solution:   Don't try getting a number for a string argument. (closes #6958)

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

index e4f05e52a688ebbbb767912c2edefd95e3bcb847..e86ec8686f2654bc74523aa916da26a70d91a82f 100644 (file)
@@ -1717,18 +1717,25 @@ do_sort_uniq(typval_T *argvars, typval_T *rettv, int sort)
            else
            {
                int         error = FALSE;
+               int         nr = 0;
 
-               i = (long)tv_get_number_chk(&argvars[1], &error);
-               if (error)
-                   goto theend;        // type error; errmsg already given
-               if (i == 1)
-                   info.item_compare_ic = TRUE;
-               else if (argvars[1].v_type != VAR_NUMBER)
-                   info.item_compare_func = tv_get_string(&argvars[1]);
-               else if (i != 0)
+               if (argvars[1].v_type == VAR_NUMBER)
                {
-                   emsg(_(e_invarg));
-                   goto theend;
+                   nr = tv_get_number_chk(&argvars[1], &error);
+                   if (error)
+                       goto theend;    // type error; errmsg already given
+                   if (nr == 1)
+                       info.item_compare_ic = TRUE;
+               }
+               if (nr != 1)
+               {
+                   if (argvars[1].v_type != VAR_NUMBER)
+                       info.item_compare_func = tv_get_string(&argvars[1]);
+                   else if (nr != 0)
+                   {
+                       emsg(_(e_invarg));
+                       goto theend;
+                   }
                }
                if (info.item_compare_func != NULL)
                {
index dcdef809001dcb25afeb55e45e5ffd0bdd9df779..f3aae7c6caa399cf7a1edbe90ef286a46ee0b4c6 100644 (file)
@@ -1299,6 +1299,11 @@ def Test_sort_return_type()
   res = [1, 2, 3]->sort()
 enddef
 
+def Test_sort_argument()
+  let res = ['b', 'a', 'c']->sort('i')
+  res->assert_equal(['a', 'b', 'c'])
+enddef
+
 def Test_getqflist_return_type()
   let l = getqflist()
   l->assert_equal([])
index ff5534ff69a674942fa49178831fe2fa4fe6b141..e06b566181ffae879b669888fb762c67200759d7 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1701,
 /**/
     1700,
 /**/