diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-09-16 23:23:36 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-09-16 23:23:36 +0200 |
commit | 08e51f446bd4bf1a0342c471163b1ed083e9eedb (patch) | |
tree | 3a1c949a2566ab73259e7b85e21a66966b253ad0 | |
parent | 9939f57b7f1c17a0142ebfe4f9e0b634158593e1 (diff) | |
download | vim-git-08e51f446bd4bf1a0342c471163b1ed083e9eedb.tar.gz |
patch 8.2.1701: Vim9: sort("i") does not workv8.2.1701
Problem: Vim9: sort("i") does not work.
Solution: Don't try getting a number for a string argument. (closes #6958)
-rw-r--r-- | src/list.c | 27 | ||||
-rw-r--r-- | src/testdir/test_vim9_func.vim | 5 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 24 insertions, 10 deletions
diff --git a/src/list.c b/src/list.c index e4f05e52a..e86ec8686 100644 --- a/src/list.c +++ b/src/list.c @@ -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) { diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index dcdef8090..f3aae7c6c 100644 --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -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([]) diff --git a/src/version.c b/src/version.c index ff5534ff6..e06b56618 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1701, +/**/ 1700, /**/ 1699, |