]> granicus.if.org Git - vim/commitdiff
patch 8.2.2619: Vim9: no test for return type of lambda v8.2.2619
authorBram Moolenaar <Bram@vim.org>
Wed, 17 Mar 2021 20:29:29 +0000 (21:29 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 17 Mar 2021 20:29:29 +0000 (21:29 +0100)
Problem:    Vim9: no test for return type of lambda.
Solution:   Add a test.

src/testdir/test_vim9_func.vim
src/version.c

index 73d8e37aa77ae410fa511f15ed5873416f52e2eb..2697c29e44fcb0a5d7cd3e752e3fbc9a26f40a0e 100644 (file)
@@ -752,11 +752,26 @@ def Test_call_lambda_args()
   CheckDefFailure(lines, 'E1167:')
 enddef
 
+def FilterWithCond(x: string, Cond: func(string): bool): bool
+  return Cond(x)
+enddef
+
 def Test_lambda_return_type()
   var lines =<< trim END
     var Ref = (): => 123
   END
   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
 
 def Test_lambda_uses_assigned_var()
index 6ac96acbda078e3b31356e74a72c7fcdc04d7eb8..74eec468a5aca60681c454d3f52c8d9ff68241b7 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2619,
 /**/
     2618,
 /**/