Skip to content

Commit 08e51f4

Browse files
committed
patch 8.2.1701: Vim9: sort("i") does not work
Problem: Vim9: sort("i") does not work. Solution: Don't try getting a number for a string argument. (closes #6958)
1 parent 9939f57 commit 08e51f4

3 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/list.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,18 +1717,25 @@ do_sort_uniq(typval_T *argvars, typval_T *rettv, int sort)
17171717
else
17181718
{
17191719
int error = FALSE;
1720+
int nr = 0;
17201721

1721-
i = (long)tv_get_number_chk(&argvars[1], &error);
1722-
if (error)
1723-
goto theend; // type error; errmsg already given
1724-
if (i == 1)
1725-
info.item_compare_ic = TRUE;
1726-
else if (argvars[1].v_type != VAR_NUMBER)
1727-
info.item_compare_func = tv_get_string(&argvars[1]);
1728-
else if (i != 0)
1722+
if (argvars[1].v_type == VAR_NUMBER)
17291723
{
1730-
emsg(_(e_invarg));
1731-
goto theend;
1724+
nr = tv_get_number_chk(&argvars[1], &error);
1725+
if (error)
1726+
goto theend; // type error; errmsg already given
1727+
if (nr == 1)
1728+
info.item_compare_ic = TRUE;
1729+
}
1730+
if (nr != 1)
1731+
{
1732+
if (argvars[1].v_type != VAR_NUMBER)
1733+
info.item_compare_func = tv_get_string(&argvars[1]);
1734+
else if (nr != 0)
1735+
{
1736+
emsg(_(e_invarg));
1737+
goto theend;
1738+
}
17321739
}
17331740
if (info.item_compare_func != NULL)
17341741
{

src/testdir/test_vim9_func.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,11 @@ def Test_sort_return_type()
12991299
res = [1, 2, 3]->sort()
13001300
enddef
13011301

1302+
def Test_sort_argument()
1303+
let res = ['b', 'a', 'c']->sort('i')
1304+
res->assert_equal(['a', 'b', 'c'])
1305+
enddef
1306+
13021307
def Test_getqflist_return_type()
13031308
let l = getqflist()
13041309
l->assert_equal([])

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1701,
753755
/**/
754756
1700,
755757
/**/

0 commit comments

Comments
 (0)