diff src/evalfunc.c @ 23849:a45a922832d4 v8.2.2466

patch 8.2.2466: max() and min() can give many error messages Commit: https://github.com/vim/vim/commit/ab65fc77c5389f7d3f788bbdc3d931561feab131 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Feb 4 22:07:16 2021 +0100 patch 8.2.2466: max() and min() can give many error messages Problem: Max() and min() can give many error messages. Solution: Bail out at the first error. (closes https://github.com/vim/vim/issues/1039, closes https://github.com/vim/vim/issues/7778)
author Bram Moolenaar <Bram@vim.org>
date Thu, 04 Feb 2021 22:15:04 +0100
parents 525c9e218c69
children a9ed31ab85c3
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -6769,12 +6769,16 @@ max_min(typval_T *argvars, typval_T *ret
 		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 *ret
 		{
 		    --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 *ret
     }
     else
 	semsg(_(e_listdictarg), domax ? "max()" : "min()");
-    rettv->vval.v_number = error ? 0 : n;
+
+    rettv->vval.v_number = n;
 }
 
 /*