Skip to content

Commit ab65fc7

Browse files
committed
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 #1039, closes #7778)
1 parent 92bb83e commit ab65fc7

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/evalfunc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6769,12 +6769,16 @@ max_min(typval_T *argvars, typval_T *rettv, int domax)
67696769
if (li != NULL)
67706770
{
67716771
n = tv_get_number_chk(&li->li_tv, &error);
6772+
if (error)
6773+
return; // type error; errmsg already given
67726774
for (;;)
67736775
{
67746776
li = li->li_next;
67756777
if (li == NULL)
67766778
break;
67776779
i = tv_get_number_chk(&li->li_tv, &error);
6780+
if (error)
6781+
return; // type error; errmsg already given
67786782
if (domax ? i > n : i < n)
67796783
n = i;
67806784
}
@@ -6799,6 +6803,8 @@ max_min(typval_T *argvars, typval_T *rettv, int domax)
67996803
{
68006804
--todo;
68016805
i = tv_get_number_chk(&HI2DI(hi)->di_tv, &error);
6806+
if (error)
6807+
return; // type error; errmsg already given
68026808
if (first)
68036809
{
68046810
n = i;
@@ -6812,7 +6818,8 @@ max_min(typval_T *argvars, typval_T *rettv, int domax)
68126818
}
68136819
else
68146820
semsg(_(e_listdictarg), domax ? "max()" : "min()");
6815-
rettv->vval.v_number = error ? 0 : n;
6821+
6822+
rettv->vval.v_number = n;
68166823
}
68176824

68186825
/*

src/testdir/test_functions.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func Test_max()
124124

125125
call assert_fails('call max(1)', 'E712:')
126126
call assert_fails('call max(v:none)', 'E712:')
127+
128+
" check we only get one error
129+
call assert_fails('call max([#{}, [1]])', ['E728:', 'E728:'])
130+
call assert_fails('call max(#{a: {}, b: [1]})', ['E728:', 'E728:'])
127131
endfunc
128132

129133
func Test_min()
@@ -137,6 +141,10 @@ func Test_min()
137141

138142
call assert_fails('call min(1)', 'E712:')
139143
call assert_fails('call min(v:none)', 'E712:')
144+
145+
" check we only get one error
146+
call assert_fails('call min([[1], #{}])', ['E745:', 'E745:'])
147+
call assert_fails('call min(#{a: [1], b: #{}})', ['E745:', 'E745:'])
140148
endfunc
141149

142150
func Test_strwidth()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2466,
753755
/**/
754756
2465,
755757
/**/

0 commit comments

Comments
 (0)