1
0
forked from aniani/vim

patch 8.2.2619: Vim9: no test for return type of lambda

Problem:    Vim9: no test for return type of lambda.
Solution:   Add a test.
This commit is contained in:
Bram Moolenaar
2021-03-17 21:29:29 +01:00
parent 3f32788000
commit 5f91e74bf9
2 changed files with 17 additions and 0 deletions

View File

@@ -752,11 +752,26 @@ def Test_call_lambda_args()
CheckDefFailure(lines, 'E1167:') CheckDefFailure(lines, 'E1167:')
enddef enddef
def FilterWithCond(x: string, Cond: func(string): bool): bool
return Cond(x)
enddef
def Test_lambda_return_type() def Test_lambda_return_type()
var lines =<< trim END var lines =<< trim END
var Ref = (): => 123 var Ref = (): => 123
END END
CheckDefAndScriptFailure(lines, 'E1157:', 1) CheckDefAndScriptFailure(lines, 'E1157:', 1)
# this works
for x in ['foo', 'boo']
echo FilterWithCond(x, (v) => v =~ '^b')
endfor
# this fails
lines =<< trim END
echo FilterWithCond('foo', (v) => v .. '^b')
END
CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected func(string): bool but got func(any): string', 1)
enddef enddef
def Test_lambda_uses_assigned_var() def Test_lambda_uses_assigned_var()

View File

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