changeset 21809:15ed135796fd v8.2.1454

patch 8.2.1454: Vim9: failure invoking lambda with wrong arguments Commit: https://github.com/vim/vim/commit/79e8db9a218ef111934594024a5cd8b1f93acada Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 14 22:16:33 2020 +0200 patch 8.2.1454: Vim9: failure invoking lambda with wrong arguments Problem: Vim9: failure invoking lambda with wrong arguments. Solution: Handle invalid arguments. Add a test.
author Bram Moolenaar <Bram@vim.org>
date Fri, 14 Aug 2020 22:30:03 +0200
parents 816b57029701
children 65ece008fe02
files src/testdir/test_vim9_expr.vim src/version.c src/vim9compile.c src/vim9execute.c
diffstat 4 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -1584,6 +1584,14 @@ def Test_expr7_lambda()
 
   call CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:')
   call CheckDefFailure(["let L = {a -> a + b}"], 'E1001:')
+
+  assert_equal('xxxyyy', 'xxx'->{a, b -> a .. b}('yyy'))
+
+  CheckDefExecFailure(["let s = 'asdf'->{a -> a}('x')"],
+        'E1106: one argument too many')
+  CheckDefExecFailure(["let s = 'asdf'->{a -> a}('x', 'y')"],
+        'E1106: 2 arguments too many')
+  CheckDefFailure(["echo 'asdf'->{a -> a}(x)"], 'E1001:')
 enddef
 
 def Test_expr7_lambda_vim9script()
--- 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 */
 /**/
+    1454,
+/**/
     1453,
 /**/
     1452,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1361,6 +1361,9 @@ generate_CALL(cctx_T *cctx, ufunc_T *ufu
 		    continue;
 		expected = ufunc->uf_arg_types[i];
 	    }
+	    else if (ufunc->uf_va_type == NULL)
+		// possibly a lambda
+		expected = &t_any;
 	    else
 		expected = ufunc->uf_va_type->tt_member;
 	    actual = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i];
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -206,7 +206,10 @@ call_dfunc(int cdf_idx, int argcount_arg
     arg_to_add = ufunc->uf_args.ga_len - argcount;
     if (arg_to_add < 0)
     {
-	iemsg("Argument count wrong?");
+	if (arg_to_add == -1)
+	    emsg(_("E1106: one argument too many"));
+	else
+	    semsg(_("E1106: %d arguments too many"), -arg_to_add);
 	return FAIL;
     }
     if (ga_grow(&ectx->ec_stack, arg_to_add + 3