changeset 23705:9092d2a4422a v8.2.2394

patch 8.2.2394: Vim9: min() and max() return type is "any" Commit: https://github.com/vim/vim/commit/9ae3705b6ebd45086ca13c0f93a93f943559bd15 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 22 22:31:10 2021 +0100 patch 8.2.2394: Vim9: min() and max() return type is "any" Problem: Vim9: min() and max() return type is "any". Solution: Use return type "number". (closes https://github.com/vim/vim/issues/7728)
author Bram Moolenaar <Bram@vim.org>
date Fri, 22 Jan 2021 22:45:03 +0100
parents 85c8bd7cca28
children 9f7e1c726d0e
files src/evalfunc.c src/testdir/test_vim9_builtin.vim src/version.c
diffstat 3 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -1219,7 +1219,7 @@ static funcentry_T global_functions[] =
     {"matchstrpos",	2, 4, FEARG_1,	    NULL,
 			ret_list_any,	    f_matchstrpos},
     {"max",		1, 1, FEARG_1,	    NULL,
-			ret_any,	    f_max},
+			ret_number,	    f_max},
     {"menu_info",	1, 2, FEARG_1,	    NULL,
 			ret_dict_any,
 #ifdef FEAT_MENU
@@ -1229,7 +1229,7 @@ static funcentry_T global_functions[] =
 #endif
 			},
     {"min",		1, 1, FEARG_1,	    NULL,
-			ret_any,	    f_min},
+			ret_number,	    f_min},
     {"mkdir",		1, 3, FEARG_1,	    NULL,
 			ret_number_bool,    f_mkdir},
     {"mode",		0, 1, FEARG_1,	    NULL,
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -655,6 +655,34 @@ def Test_maparg_mapset()
   nunmap <F3>
 enddef
 
+def Test_max()
+  g:flag = true
+  var l1: list<number> = g:flag
+          ? [1, max([2, 3])]
+          : [4, 5]
+  assert_equal([1, 3], l1)
+
+  g:flag = false
+  var l2: list<number> = g:flag
+          ? [1, max([2, 3])]
+          : [4, 5]
+  assert_equal([4, 5], l2)
+enddef
+
+def Test_min()
+  g:flag = true
+  var l1: list<number> = g:flag
+          ? [1, min([2, 3])]
+          : [4, 5]
+  assert_equal([1, 2], l1)
+
+  g:flag = false
+  var l2: list<number> = g:flag
+          ? [1, min([2, 3])]
+          : [4, 5]
+  assert_equal([4, 5], l2)
+enddef
+
 def Test_nr2char()
   nr2char(97, true)->assert_equal('a')
 enddef
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2394,
+/**/
     2393,
 /**/
     2392,