changeset 21180:dde4c2e84f5c v8.2.1141

patch 8.2.1141: Vim9: return type of filter() is any Commit: https://github.com/vim/vim/commit/0d94ad69586972e7522ec6ca1441a517af2ade7a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 5 20:16:41 2020 +0200 patch 8.2.1141: Vim9: return type of filter() is any Problem: Vim9: return type of filter() is any. Solution: Use type of the argument.
author Bram Moolenaar <Bram@vim.org>
date Sun, 05 Jul 2020 20:30:06 +0200
parents 2bf0ee9ae1c7
children 7ce93ec8ac30
files src/evalfunc.c src/testdir/test_vim9_func.vim src/version.c
diffstat 3 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -581,7 +581,7 @@ static funcentry_T global_functions[] =
     {"file_readable",	1, 1, FEARG_1,	  ret_number,	f_filereadable}, // obsolete
     {"filereadable",	1, 1, FEARG_1,	  ret_number,	f_filereadable},
     {"filewritable",	1, 1, FEARG_1,	  ret_number,	f_filewritable},
-    {"filter",		2, 2, FEARG_1,	  ret_any,	f_filter},
+    {"filter",		2, 2, FEARG_1,	  ret_first_arg, f_filter},
     {"finddir",		1, 3, FEARG_1,	  ret_string,	f_finddir},
     {"findfile",	1, 3, FEARG_1,	  ret_string,	f_findfile},
     {"flatten",		1, 2, FEARG_1,	  ret_list_any,	f_flatten},
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -918,6 +918,15 @@ def Test_extend_return_type()
   assert_equal(6, res)
 enddef
 
+def Test_filter_return_type()
+  let l = filter([1, 2, 3], {-> 1})
+  let res = 0
+  for n in l
+    res += n
+  endfor
+  assert_equal(6, res)
+enddef
+
 def Line_continuation_in_def(dir: string = ''): string
     let path: string = empty(dir)
             \ ? 'empty'
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1141,
+/**/
     1140,
 /**/
     1139,