diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-25 10:35:20 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-11-25 10:38:16 +0800 |
commit | 5bdd787a7a2274d802479498ccd1d1f0c4fc589b (patch) | |
tree | 86475bce78f2604dde5e5e5f6bac880824ef8d14 | |
parent | 2b55d09314500c0049427cd51e873cc4eac223b2 (diff) | |
download | rneovim-5bdd787a7a2274d802479498ccd1d1f0c4fc589b.tar.gz rneovim-5bdd787a7a2274d802479498ccd1d1f0c4fc589b.tar.bz2 rneovim-5bdd787a7a2274d802479498ccd1d1f0c4fc589b.zip |
vim-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 vim/vim#1039, closes vim/vim#7778)
https://github.com/vim/vim/commit/ab65fc77c5389f7d3f788bbdc3d931561feab131
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/eval/funcs.c | 5 | ||||
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 8 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 8ab1178b17..96c483ea75 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -5245,7 +5245,7 @@ static void max_min(const typval_T *const tv, typval_T *const rettv, const bool TV_LIST_ITER_CONST(tv->vval.v_list, li, { const varnumber_T i = tv_get_number_chk(TV_LIST_ITEM_TV(li), &error); if (error) { - return; + return; // type error; errmsg already given } if (domax ? i > n : i < n) { n = i; @@ -5258,7 +5258,7 @@ static void max_min(const typval_T *const tv, typval_T *const rettv, const bool TV_DICT_ITER(tv->vval.v_dict, di, { const varnumber_T i = tv_get_number_chk(&di->di_tv, &error); if (error) { - return; + return; // type error; errmsg already given } if (domax ? i > n : i < n) { n = i; @@ -5268,6 +5268,7 @@ static void max_min(const typval_T *const tv, typval_T *const rettv, const bool semsg(_(e_listdictarg), domax ? "max()" : "min()"); return; } + rettv->vval.v_number = n; } diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 5ff544ab55..f0cd8ee878 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -110,6 +110,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() @@ -123,6 +127,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() |