changeset 26763:9cb27a68a01b v8.2.3910

patch 8.2.3910: when compare function of sort() fails it does not abort Commit: https://github.com/vim/vim/commit/23018f2d4b6f85512af117d346eee9b14a4637a6 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 27 11:54:37 2021 +0000 patch 8.2.3910: when compare function of sort() fails it does not abort Problem: When the compare function of sort() produces and error then sort() does not abort. Solution: Check if did_emsg was incremented.
author Bram Moolenaar <Bram@vim.org>
date Mon, 27 Dec 2021 13:00:04 +0100
parents 3b3d7878f9fb
children dc416a3203d1
files src/list.c src/testdir/test_vim9_builtin.vim src/version.c
diffstat 3 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/list.c
+++ b/src/list.c
@@ -1919,6 +1919,7 @@ item_compare2(const void *s1, const void
     char_u	*func_name;
     partial_T	*partial = sortinfo->item_compare_partial;
     funcexe_T	funcexe;
+    int		did_emsg_before = did_emsg;
 
     // shortcut after failure in previous call; compare all items equal
     if (sortinfo->item_compare_func_err)
@@ -1946,7 +1947,7 @@ item_compare2(const void *s1, const void
     clear_tv(&argv[0]);
     clear_tv(&argv[1]);
 
-    if (res == FAIL)
+    if (res == FAIL || did_emsg > did_emsg_before)
 	res = ITEM_COMPARE_FAIL;
     else
     {
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -3524,6 +3524,17 @@ def Test_sort_argument()
   CheckDefAndScriptFailure(['sort([1], "", [1])'], ['E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3'])
 enddef
 
+def Test_sort_compare_func_fails()
+  var lines =<< trim END
+    vim9script
+    echo ['a', 'b', 'c']->sort((a: number, b: number) => 0)
+  END
+  writefile(lines, 'Xbadsort')
+  assert_fails('source Xbadsort', ['E1013:', 'E702:'])
+
+  delete('Xbadsort')
+enddef
+
 def Test_spellbadword()
   CheckDefAndScriptFailure(['spellbadword(100)'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1'])
   spellbadword('good')->assert_equal(['', ''])
--- a/src/version.c
+++ b/src/version.c
@@ -750,6 +750,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3910,
+/**/
     3909,
 /**/
     3908,