]> granicus.if.org Git - vim/commitdiff
patch 8.2.2942: Vim9: error when calling function with too few arguments v8.2.2942
authorBram Moolenaar <Bram@vim.org>
Sat, 5 Jun 2021 16:15:09 +0000 (18:15 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 5 Jun 2021 16:15:09 +0000 (18:15 +0200)
Problem:    Vim9: internal error when calling function with too few arguments
Solution:   Check for argument count to be too few. (closes #8325)

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

index 00e2d565d0a559e2a1f1b0524b89e3a47d01316b..94a752ae681fef5019ebf08271cfbd828f396ec1 100644 (file)
@@ -419,3 +419,7 @@ EXTERN char e_cannot_open_terminal_from_command_line_window[]
        INIT(= N_("E1188: Cannot open a terminal from the command line window"));
 EXTERN char e_cannot_use_legacy_with_command_str[]
        INIT(= N_("E1189: Cannot use :legacy with this command: %s"));
+EXTERN char e_one_argument_too_few[]
+       INIT(= N_("E1190: One argument too few"));
+EXTERN char e_nr_arguments_too_few[]
+       INIT(= N_("E1190: %d arguments too few"));
index 3fa5eb306564d36c39cb45d3a5d248ec39aa222a..9cae4a34e187beee9664311631a88af336b78d2f 100644 (file)
@@ -810,6 +810,15 @@ def Test_map_function_arg()
       assert_equal(['0:a', '1:b', '2:c'], l)
   END
   CheckDefAndScriptSuccess(lines)
+
+  lines =<< trim END
+      range(3)->map((a, b, c) => a + b + c)
+  END
+  CheckDefExecAndScriptFailure(lines, 'E1190: One argument too few')
+  lines =<< trim END
+      range(3)->map((a, b, c, d) => a + b + c + d)
+  END
+  CheckDefExecAndScriptFailure(lines, 'E1190: 2 arguments too few')
 enddef
 
 def Test_map_item_type()
index 0f539ca2ee82ee581c8011c009d10864c99e956e..ce8273f483f10497cf700191f754c407dcf99496 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2942,
 /**/
     2941,
 /**/
index 9826678293fed7774f462ef1e707f0eb05f7f898..c2a7de50d6efeed0e803c5134312c43c09720ae0 100644 (file)
@@ -4234,6 +4234,14 @@ call_def_function(
            semsg(_(e_nr_arguments_too_many), idx);
        goto failed_early;
     }
+    else if (idx < 0)
+    {
+       if (idx == -1)
+           emsg(_(e_one_argument_too_few));
+       else
+           semsg(_(e_nr_arguments_too_few), -idx);
+       goto failed_early;
+    }
 
     // Put arguments on the stack, but no more than what the function expects.
     // A lambda can be called with more arguments than it uses.