mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 9.0.1138: crash when expecting varargs but it is something else
Problem: Crash when expecting varargs but it is something else. Solution: Only use the member when the type is a list. (closes #11774)
This commit is contained in:
@@ -1869,6 +1869,20 @@ def Test_call_varargs_only()
|
|||||||
v9.CheckDefFailure(['g:MyVarargsOnly("one", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number')
|
v9.CheckDefFailure(['g:MyVarargsOnly("one", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number')
|
||||||
enddef
|
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()
|
def Test_using_var_as_arg()
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
def Func(x: number)
|
def Func(x: number)
|
||||||
|
@@ -695,6 +695,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1138,
|
||||||
/**/
|
/**/
|
||||||
1137,
|
1137,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1841,7 +1841,13 @@ check_func_args_from_type(
|
|||||||
type_T *expected;
|
type_T *expected;
|
||||||
|
|
||||||
if (varargs && i >= type->tt_argcount - 1)
|
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
|
else if (i >= type->tt_min_argcount
|
||||||
&& actual->tt_type == VAR_SPECIAL)
|
&& actual->tt_type == VAR_SPECIAL)
|
||||||
expected = &t_any;
|
expected = &t_any;
|
||||||
|
@@ -932,8 +932,10 @@ check_argument_types(
|
|||||||
if (varargs && i >= type->tt_argcount - 1)
|
if (varargs && i >= type->tt_argcount - 1)
|
||||||
{
|
{
|
||||||
expected = type->tt_args[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;
|
expected = expected->tt_member;
|
||||||
|
if (expected == NULL)
|
||||||
|
expected = &t_any;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
expected = type->tt_args[i];
|
expected = type->tt_args[i];
|
||||||
|
Reference in New Issue
Block a user