]> granicus.if.org Git - vim/commitdiff
patch 8.2.2747: Vim9: not always an error for too many function arguments v8.2.2747
authorBram Moolenaar <Bram@vim.org>
Sat, 10 Apr 2021 18:10:26 +0000 (20:10 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 10 Apr 2021 18:10:26 +0000 (20:10 +0200)
Problem:    Vim9: not always an error for too many function arguments.
Solution:   Check for getting too many arguments.

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

index f537eef82c3d343db3ba95c338c23b251117e59c..5c13d512775264f14704e5ea0399b68c5b00fd46 100644 (file)
@@ -506,7 +506,7 @@ def Test_filter_wrong_dict_key_type()
 enddef
 
 def Test_filter_return_type()
-  var l = filter([1, 2, 3], () => 1)
+  var l = filter([1, 2, 3], (_, _) => 1)
   var res = 0
   for n in l
     res += n
@@ -516,7 +516,7 @@ 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')
+  var res = dict->filter((k, _) => k =~ 'a' && k !~ 'b')
   res->assert_equal({aa: [1], ac: [3]})
 enddef
 
index c02a324d4c0a511f927bf12bcd068e9e3950d816..6b353dd6993190e3d4207bc5626a01cecdebd196 100644 (file)
@@ -2102,7 +2102,7 @@ def Test_script_var_in_lambda()
   var lines =<< trim END
       vim9script
       var script = 'test'
-      assert_equal(['test'], map(['one'], () => script))
+      assert_equal(['test'], map(['one'], (_, _) => script))
   END
   CheckScriptSuccess(lines)
 enddef
@@ -2355,7 +2355,7 @@ def Test_block_scoped_var()
         var x = ['a', 'b', 'c']
         if 1
           var y = 'x'
-          map(x, () => y)
+          map(x, (_, _) => y)
         endif
         var z = x
         assert_equal(['x', 'x', 'x'], z)
@@ -2654,6 +2654,17 @@ def Test_ignored_argument()
   CheckDefAndScriptFailure(lines, 'E1181:', 1)
 enddef
 
+def Test_too_many_arguments()
+  var lines =<< trim END
+    echo [0, 1, 2]->map(() => 123)
+  END
+  CheckDefExecAndScriptFailure(lines, 'E1106: 2 arguments too many', 1)
+
+  lines =<< trim END
+    echo [0, 1, 2]->map((_) => 123)
+  END
+  CheckDefExecAndScriptFailure(lines, 'E1106: One argument too many', 1)
+enddef
 
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index bbbc92abbbf0b65afcb0f62384d0936d843b218b..9fca01a86d34d9fa4d86c993937828393d21da6f 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2747,
 /**/
     2746,
 /**/
index a49d305532605d8cc1cf74b47bca2b25d41e55d7..e7885ad70081d678239ea0d237b9d064c5b122bd 100644 (file)
@@ -1336,6 +1336,16 @@ call_def_function(
     ga_init2(&ectx.ec_trystack, sizeof(trycmd_T), 10);
     ga_init2(&ectx.ec_funcrefs, sizeof(partial_T *), 10);
 
+    idx = argc - ufunc->uf_args.ga_len;
+    if (idx > 0 && ufunc->uf_va_name == NULL)
+    {
+       if (idx == 1)
+           emsg(_(e_one_argument_too_many));
+       else
+           semsg(_(e_nr_arguments_too_many), idx);
+       return FAIL;
+    }
+
     // 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