1
0
forked from aniani/vim

patch 8.2.3911: Vim9: type check for filter() does not accept unknown

Problem:    Vim9: type check for filter() does not accept unknown.
Solution:   Also accept unknown for the return type. (closes #9413)
This commit is contained in:
Bram Moolenaar
2021-12-27 12:29:19 +00:00
parent 23018f2d4b
commit ef8f04b1d1
3 changed files with 9 additions and 0 deletions

View File

@@ -494,6 +494,7 @@ arg_filter_func(type_T *type, argcontext_T *context)
if (type->tt_type == VAR_FUNC
&& !(type->tt_member->tt_type == VAR_BOOL
|| type->tt_member->tt_type == VAR_NUMBER
|| type->tt_member->tt_type == VAR_UNKNOWN
|| type->tt_member->tt_type == VAR_ANY))
{
arg_type_mismatch(&t_func_bool, type, context->arg_idx + 1);

View File

@@ -1253,6 +1253,12 @@ def Test_filter()
assert_equal([], filter([1, 2, 3], '0'))
assert_equal([1, 2, 3], filter([1, 2, 3], '1'))
assert_equal({b: 20}, filter({a: 10, b: 20}, 'v:val == 20'))
def GetFiltered(): list<number>
var Odd: func = (_, v) => v % 2
return range(3)->filter(Odd)
enddef
assert_equal([1], GetFiltered())
enddef
def Test_filter_wrong_dict_key_type()

View File

@@ -749,6 +749,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3911,
/**/
3910,
/**/