To: vim_dev@googlegroups.com Subject: Patch 7.4.1464 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1464 Problem: When the argument of sort() is zero or empty it fails. Solution: Make zero work as documented. (suggested by Yasuhiro Matsumoto) Files: src/eval.c, src/testdir/test_sort.vim *** ../vim-7.4.1463/src/eval.c 2016-02-29 21:05:43.539766722 +0100 --- src/eval.c 2016-02-29 22:01:12.208263543 +0100 *************** *** 19195,19205 **** goto theend; /* type error; errmsg already given */ if (i == 1) info.item_compare_ic = TRUE; ! else info.item_compare_func = get_tv_string(&argvars[1]); if (info.item_compare_func != NULL) { ! if (STRCMP(info.item_compare_func, "n") == 0) { info.item_compare_func = NULL; info.item_compare_numeric = TRUE; --- 19195,19215 ---- 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 = get_tv_string(&argvars[1]); + else if (i != 0) + { + EMSG(_(e_invarg)); + goto theend; + } if (info.item_compare_func != NULL) { ! if (*info.item_compare_func == NUL) ! { ! /* empty string means default sort */ ! info.item_compare_func = NULL; ! } ! else if (STRCMP(info.item_compare_func, "n") == 0) { info.item_compare_func = NULL; info.item_compare_numeric = TRUE; *** ../vim-7.4.1463/src/testdir/test_sort.vim 2016-02-22 23:50:24.256520848 +0100 --- src/testdir/test_sort.vim 2016-02-29 22:04:57.213884438 +0100 *************** *** 35,37 **** --- 35,45 ---- " test ability to call sort() from a compare function call assert_equal([1, 3, 5], sort([3, 1, 5], 'Compare1')) endfunc + + func Test_sort_default() + " docs say omitted, empty or zero argument sorts on string representation. + call assert_equal(["2", 1, 3.3], sort([3.3, 1, "2"])) + call assert_equal(["2", 1, 3.3], sort([3.3, 1, "2"], '')) + call assert_equal(["2", 1, 3.3], sort([3.3, 1, "2"], 0)) + call assert_fails('call sort([3.3, 1, "2"], 3)', "E474") + endfunc *** ../vim-7.4.1463/src/version.c 2016-02-29 21:38:22.206751785 +0100 --- src/version.c 2016-02-29 21:47:25.493005463 +0100 *************** *** 745,746 **** --- 745,748 ---- { /* Add new patch number below this line */ + /**/ + 1464, /**/ -- SOLDIER: Where did you get the coconuts? ARTHUR: Through ... We found them. SOLDIER: Found them? In Mercea. The coconut's tropical! "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///