Skip to content

Commit 5f91e74

Browse files
committed
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.
1 parent 3f32788 commit 5f91e74

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/testdir/test_vim9_func.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,26 @@ def Test_call_lambda_args()
752752
CheckDefFailure(lines, 'E1167:')
753753
enddef
754754

755+
def FilterWithCond(x: string, Cond: func(string): bool): bool
756+
return Cond(x)
757+
enddef
758+
755759
def Test_lambda_return_type()
756760
var lines =<< trim END
757761
var Ref = (): => 123
758762
END
759763
CheckDefAndScriptFailure(lines, 'E1157:', 1)
764+
765+
# this works
766+
for x in ['foo', 'boo']
767+
echo FilterWithCond(x, (v) => v =~ '^b')
768+
endfor
769+
770+
# this fails
771+
lines =<< trim END
772+
echo FilterWithCond('foo', (v) => v .. '^b')
773+
END
774+
CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected func(string): bool but got func(any): string', 1)
760775
enddef
761776

762777
def Test_lambda_uses_assigned_var()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2619,
753755
/**/
754756
2618,
755757
/**/

0 commit comments

Comments
 (0)