summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-07-26 18:33:09 +0200
committerBram Moolenaar <Bram@vim.org>2020-07-26 18:33:09 +0200
commit01865ade85d2508639e24aaca5948b09fb284a82 (patch)
tree23b3c3d7c3124101b560e7b517a7d33860dac806 /src
parentace6132aa8c5fce9d4965e1f2e3a42071815b9de (diff)
patch 8.2.1302: Vim9: varargs arg after optional arg does not workv8.2.1302
Problem: Vim9: varargs arg after optional arg does not work Solution: Check for the "..." first. (issue #6507)
Diffstat (limited to 'src')
-rw-r--r--src/testdir/test_vim9_func.vim22
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c10
3 files changed, 29 insertions, 5 deletions
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 0d39d57649..c05e98e704 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -376,6 +376,28 @@ def Test_call_funcref()
assert_equal([1, 2, 3], g:echo)
END
CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ def OptAndVar(nr: number, opt = 12, ...l: list<number>): number
+ g:optarg = opt
+ g:listarg = l
+ return nr
+ enddef
+ let Funcref: func(number, ?number, ...list<number>): number = function('OptAndVar')
+ assert_equal(10, Funcref(10))
+ assert_equal(12, g:optarg)
+ assert_equal([], g:listarg)
+
+ assert_equal(11, Funcref(11, 22))
+ assert_equal(22, g:optarg)
+ assert_equal([], g:listarg)
+
+ assert_equal(17, Funcref(17, 18, 1, 2, 3))
+ assert_equal(18, g:optarg)
+ assert_equal([1, 2, 3], g:listarg)
+ END
+ CheckScriptSuccess(lines)
enddef
let SomeFunc = function('len')
diff --git a/src/version.c b/src/version.c
index 2481434407..e969ab0f35 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1302,
+/**/
1301,
/**/
1300,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 31e761284e..8efb1f672f 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2106,16 +2106,16 @@ parse_type(char_u **arg, garray_T *type_gap)
first_optional = argcount;
++p;
}
- else if (first_optional != -1)
- {
- emsg(_("E1007: mandatory argument after optional argument"));
- return &t_any;
- }
else if (STRNCMP(p, "...", 3) == 0)
{
flags |= TTFLAG_VARARGS;
p += 3;
}
+ else if (first_optional != -1)
+ {
+ emsg(_("E1007: mandatory argument after optional argument"));
+ return &t_any;
+ }
arg_type[argcount++] = parse_type(&p, type_gap);