Skip to content

Commit 79e8db9

Browse files
committed
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.
1 parent 8de2f44 commit 79e8db9

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/testdir/test_vim9_expr.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,14 @@ def Test_expr7_lambda()
15841584

15851585
call CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:')
15861586
call CheckDefFailure(["let L = {a -> a + b}"], 'E1001:')
1587+
1588+
assert_equal('xxxyyy', 'xxx'->{a, b -> a .. b}('yyy'))
1589+
1590+
CheckDefExecFailure(["let s = 'asdf'->{a -> a}('x')"],
1591+
'E1106: one argument too many')
1592+
CheckDefExecFailure(["let s = 'asdf'->{a -> a}('x', 'y')"],
1593+
'E1106: 2 arguments too many')
1594+
CheckDefFailure(["echo 'asdf'->{a -> a}(x)"], 'E1001:')
15871595
enddef
15881596

15891597
def Test_expr7_lambda_vim9script()

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1454,
757759
/**/
758760
1453,
759761
/**/

src/vim9compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,9 @@ generate_CALL(cctx_T *cctx, ufunc_T *ufunc, int pushed_argcount)
13611361
continue;
13621362
expected = ufunc->uf_arg_types[i];
13631363
}
1364+
else if (ufunc->uf_va_type == NULL)
1365+
// possibly a lambda
1366+
expected = &t_any;
13641367
else
13651368
expected = ufunc->uf_va_type->tt_member;
13661369
actual = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i];

src/vim9execute.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ call_dfunc(int cdf_idx, int argcount_arg, ectx_T *ectx)
206206
arg_to_add = ufunc->uf_args.ga_len - argcount;
207207
if (arg_to_add < 0)
208208
{
209-
iemsg("Argument count wrong?");
209+
if (arg_to_add == -1)
210+
emsg(_("E1106: one argument too many"));
211+
else
212+
semsg(_("E1106: %d arguments too many"), -arg_to_add);
210213
return FAIL;
211214
}
212215
if (ga_grow(&ectx->ec_stack, arg_to_add + 3

0 commit comments

Comments
 (0)