0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.2218: Vim9: failure if passing more args to lambda than expected

Problem:    Vim9: failure if passing more arguments to a lambda than expected.
Solution:   Only put expected arguments on the stack. (closes #7548)
This commit is contained in:
Bram Moolenaar
2020-12-25 20:24:51 +01:00
parent 20a762987e
commit fc0e8f5c3e
3 changed files with 12 additions and 2 deletions

View File

@@ -321,6 +321,11 @@ def Test_filter_return_type()
res->assert_equal(6) res->assert_equal(6)
enddef enddef
def Test_filter_missing_argument()
var dict = {aa: [1], ab: [2], ac: [3], de: [4]}
var res = dict->filter({k -> k =~ 'a' && k !~ 'b'})
res->assert_equal({aa: [1], ac: [3]})
enddef
def Test_garbagecollect() def Test_garbagecollect()
garbagecollect(true) garbagecollect(true)

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2218,
/**/ /**/
2217, 2217,
/**/ /**/

View File

@@ -1020,8 +1020,11 @@ call_def_function(
ga_init2(&ectx.ec_trystack, sizeof(trycmd_T), 10); ga_init2(&ectx.ec_trystack, sizeof(trycmd_T), 10);
ga_init2(&ectx.ec_funcrefs, sizeof(partial_T *), 10); ga_init2(&ectx.ec_funcrefs, sizeof(partial_T *), 10);
// Put arguments on the stack. // Put arguments on the stack, but no more than what the function expects.
for (idx = 0; idx < argc; ++idx) // A lambda can be called with more arguments than it uses.
for (idx = 0; idx < argc
&& (ufunc->uf_va_name != NULL || idx < ufunc->uf_args.ga_len);
++idx)
{ {
if (ufunc->uf_arg_types != NULL && idx < ufunc->uf_args.ga_len if (ufunc->uf_arg_types != NULL && idx < ufunc->uf_args.ga_len
&& check_typval_type(ufunc->uf_arg_types[idx], &argv[idx], && check_typval_type(ufunc->uf_arg_types[idx], &argv[idx],