summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-06-05 18:15:09 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-05 18:15:09 +0200
commit8da6d6db340069b3307e6bce3cdd40441197efce (patch)
treef52aca5f60babf5e0ebf4ff4b47f78322cf6d94e
parentb288ba9f1dd29ba34f236e3099f779d5ab130227 (diff)
downloadvim-git-8da6d6db340069b3307e6bce3cdd40441197efce.tar.gz
patch 8.2.2942: Vim9: error when calling function with too few argumentsv8.2.2942
Problem: Vim9: internal error when calling function with too few arguments Solution: Check for argument count to be too few. (closes #8325)
-rw-r--r--src/errors.h4
-rw-r--r--src/testdir/test_vim9_builtin.vim9
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c8
4 files changed, 23 insertions, 0 deletions
diff --git a/src/errors.h b/src/errors.h
index 00e2d565d..94a752ae6 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -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"));
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index 3fa5eb306..9cae4a34e 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -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()
diff --git a/src/version.c b/src/version.c
index 0f539ca2e..ce8273f48 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2942,
+/**/
2941,
/**/
2940,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 982667829..c2a7de50d 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -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.