diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-08-14 22:16:33 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-08-14 22:16:33 +0200 |
commit | 79e8db9a218ef111934594024a5cd8b1f93acada (patch) | |
tree | 980ed11ba0d24efa15ee4e10f628f54553ac697f | |
parent | 8de2f44ac6af2276587a2e44a0d5fe1dc6789eb3 (diff) | |
download | vim-git-79e8db9a218ef111934594024a5cd8b1f93acada.tar.gz |
patch 8.2.1454: Vim9: failure invoking lambda with wrong argumentsv8.2.1454
Problem: Vim9: failure invoking lambda with wrong arguments.
Solution: Handle invalid arguments. Add a test.
-rw-r--r-- | src/testdir/test_vim9_expr.vim | 8 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 3 | ||||
-rw-r--r-- | src/vim9execute.c | 5 |
4 files changed, 17 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index 48c1cf219..fb07586bc 100644 --- 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 index cebea6458..e6d929e1a 100644 --- 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 index bdb0f064e..5c4547d08 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -1361,6 +1361,9 @@ generate_CALL(cctx_T *cctx, ufunc_T *ufunc, int pushed_argcount) 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 index c87ac79e3..0f7f18c33 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -206,7 +206,10 @@ call_dfunc(int cdf_idx, int argcount_arg, ectx_T *ectx) 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 |