]> granicus.if.org Git - vim/commitdiff
patch 8.2.2218: Vim9: failure if passing more args to lambda than expected v8.2.2218
authorBram Moolenaar <Bram@vim.org>
Fri, 25 Dec 2020 19:24:51 +0000 (20:24 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 25 Dec 2020 19:24:51 +0000 (20:24 +0100)
Problem:    Vim9: failure if passing more arguments to a lambda than expected.
Solution:   Only put expected arguments on the stack. (closes #7548)

src/testdir/test_vim9_builtin.vim
src/version.c
src/vim9execute.c

index 0f03d1f5c58727a47cd94fe611de06c4b1d5c57c..4abdcdba640b19ba0508ed73507548c41f1fafb4 100644 (file)
@@ -321,6 +321,11 @@ def Test_filter_return_type()
   res->assert_equal(6)
 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()
   garbagecollect(true)
index f48c2afd3cbf4d03cf401c292c0b9f7c1d3e7bd1..90ef966cca0927d2bdf30cf675392c2304ccb6b9 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2218,
 /**/
     2217,
 /**/
index 4d889916763d3fee22754d2855fc443ebb8c4640..b3abee9ef8b396092c04f1bab5027e1dc9de408b 100644 (file)
@@ -1020,8 +1020,11 @@ call_def_function(
     ga_init2(&ectx.ec_trystack, sizeof(trycmd_T), 10);
     ga_init2(&ectx.ec_funcrefs, sizeof(partial_T *), 10);
 
-    // Put arguments on the stack.
-    for (idx = 0; idx < argc; ++idx)
+    // Put arguments on the stack, but no more than what the function expects.
+    // 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
                && check_typval_type(ufunc->uf_arg_types[idx], &argv[idx],