Skip to content

Commit 01865ad

Browse files
committed
patch 8.2.1302: Vim9: varargs arg after optional arg does not work
Problem: Vim9: varargs arg after optional arg does not work Solution: Check for the "..." first. (issue #6507)
1 parent ace6132 commit 01865ad

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/testdir/test_vim9_func.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,28 @@ def Test_call_funcref()
376376
assert_equal([1, 2, 3], g:echo)
377377
END
378378
CheckScriptSuccess(lines)
379+
380+
lines =<< trim END
381+
vim9script
382+
def OptAndVar(nr: number, opt = 12, ...l: list<number>): number
383+
g:optarg = opt
384+
g:listarg = l
385+
return nr
386+
enddef
387+
let Funcref: func(number, ?number, ...list<number>): number = function('OptAndVar')
388+
assert_equal(10, Funcref(10))
389+
assert_equal(12, g:optarg)
390+
assert_equal([], g:listarg)
391+
392+
assert_equal(11, Funcref(11, 22))
393+
assert_equal(22, g:optarg)
394+
assert_equal([], g:listarg)
395+
396+
assert_equal(17, Funcref(17, 18, 1, 2, 3))
397+
assert_equal(18, g:optarg)
398+
assert_equal([1, 2, 3], g:listarg)
399+
END
400+
CheckScriptSuccess(lines)
379401
enddef
380402

381403
let SomeFunc = function('len')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1302,
757759
/**/
758760
1301,
759761
/**/

src/vim9compile.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,16 +2106,16 @@ parse_type(char_u **arg, garray_T *type_gap)
21062106
first_optional = argcount;
21072107
++p;
21082108
}
2109-
else if (first_optional != -1)
2110-
{
2111-
emsg(_("E1007: mandatory argument after optional argument"));
2112-
return &t_any;
2113-
}
21142109
else if (STRNCMP(p, "...", 3) == 0)
21152110
{
21162111
flags |= TTFLAG_VARARGS;
21172112
p += 3;
21182113
}
2114+
else if (first_optional != -1)
2115+
{
2116+
emsg(_("E1007: mandatory argument after optional argument"));
2117+
return &t_any;
2118+
}
21192119

21202120
arg_type[argcount++] = parse_type(&p, type_gap);
21212121

0 commit comments

Comments
 (0)