]> granicus.if.org Git - vim/commitdiff
patch 8.2.2466: max() and min() can give many error messages v8.2.2466
authorBram Moolenaar <Bram@vim.org>
Thu, 4 Feb 2021 21:07:16 +0000 (22:07 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 4 Feb 2021 21:07:16 +0000 (22:07 +0100)
Problem:    Max() and min() can give many error messages.
Solution:   Bail out at the first error. (closes #1039, closes #7778)

src/evalfunc.c
src/testdir/test_functions.vim
src/version.c

index 0b4b5021adbf1cec03791ed0a15c53b45cefebff..f15139f362c7dfb2f6e17ccab2f045e081f84fc5 100644 (file)
@@ -6769,12 +6769,16 @@ max_min(typval_T *argvars, typval_T *rettv, int domax)
                if (li != NULL)
                {
                    n = tv_get_number_chk(&li->li_tv, &error);
+                   if (error)
+                       return; // type error; errmsg already given
                    for (;;)
                    {
                        li = li->li_next;
                        if (li == NULL)
                            break;
                        i = tv_get_number_chk(&li->li_tv, &error);
+                       if (error)
+                           return; // type error; errmsg already given
                        if (domax ? i > n : i < n)
                            n = i;
                    }
@@ -6799,6 +6803,8 @@ max_min(typval_T *argvars, typval_T *rettv, int domax)
                {
                    --todo;
                    i = tv_get_number_chk(&HI2DI(hi)->di_tv, &error);
+                   if (error)
+                       return; // type error; errmsg already given
                    if (first)
                    {
                        n = i;
@@ -6812,7 +6818,8 @@ max_min(typval_T *argvars, typval_T *rettv, int domax)
     }
     else
        semsg(_(e_listdictarg), domax ? "max()" : "min()");
-    rettv->vval.v_number = error ? 0 : n;
+
+    rettv->vval.v_number = n;
 }
 
 /*
index b82f72fd028c5f221c5b1f6510f4c1a5394a6890..64afe548178417a1d972e6576849cf5c24d2a4e6 100644 (file)
@@ -124,6 +124,10 @@ func Test_max()
 
   call assert_fails('call max(1)', 'E712:')
   call assert_fails('call max(v:none)', 'E712:')
+
+  " check we only get one error
+  call assert_fails('call max([#{}, [1]])', ['E728:', 'E728:'])
+  call assert_fails('call max(#{a: {}, b: [1]})', ['E728:', 'E728:'])
 endfunc
 
 func Test_min()
@@ -137,6 +141,10 @@ func Test_min()
 
   call assert_fails('call min(1)', 'E712:')
   call assert_fails('call min(v:none)', 'E712:')
+
+  " check we only get one error
+  call assert_fails('call min([[1], #{}])', ['E745:', 'E745:'])
+  call assert_fails('call min(#{a: [1], b: #{}})', ['E745:', 'E745:'])
 endfunc
 
 func Test_strwidth()
index 7f672301ecd3babfcbf989cd0b884e01419a691b..0ea7fb4493a69fd76347fe03dfea547204ba933f 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2466,
 /**/
     2465,
 /**/