# HG changeset patch # User Bram Moolenaar # Date 1597437003 -7200 # Node ID 15ed135796fd448a41523096209c3753423ae3ec # Parent 816b570297019f84830d07f21d655a96f0fbcf8d patch 8.2.1454: Vim9: failure invoking lambda with wrong arguments Commit: https://github.com/vim/vim/commit/79e8db9a218ef111934594024a5cd8b1f93acada Author: Bram Moolenaar 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. diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim --- 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() diff --git a/src/version.c b/src/version.c --- 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, diff --git a/src/vim9compile.c b/src/vim9compile.c --- 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]; diff --git a/src/vim9execute.c b/src/vim9execute.c --- 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