Problem: Crash when expecting varargs but it is something else.
Solution: Only use the member when the type is a list. (closes #11774)
v9.CheckDefFailure(['g:MyVarargsOnly("one", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number')
enddef
+def Test_varargs_mismatch()
+ var lines =<< trim END
+ vim9script
+
+ def Map(Fn: func(...any): number): number
+ return Fn('12')
+ enddef
+
+ var res = Map((v) => str2nr(v))
+ assert_equal(12, res)
+ END
+ v9.CheckScriptSuccess(lines)
+enddef
+
def Test_using_var_as_arg()
var lines =<< trim END
def Func(x: number)
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1138,
/**/
1137,
/**/
type_T *expected;
if (varargs && i >= type->tt_argcount - 1)
- expected = type->tt_args[type->tt_argcount - 1]->tt_member;
+ {
+ expected = type->tt_args[type->tt_argcount - 1];
+ if (expected != NULL && expected->tt_type == VAR_LIST)
+ expected = expected->tt_member;
+ if (expected == NULL)
+ expected = &t_any;
+ }
else if (i >= type->tt_min_argcount
&& actual->tt_type == VAR_SPECIAL)
expected = &t_any;
if (varargs && i >= type->tt_argcount - 1)
{
expected = type->tt_args[type->tt_argcount - 1];
- if (expected != NULL)
+ if (expected != NULL && expected->tt_type == VAR_LIST)
expected = expected->tt_member;
+ if (expected == NULL)
+ expected = &t_any;
}
else
expected = type->tt_args[i];