mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.2.0548: Vim9: not all possible func type errors tested
Problem: Vim9: not all possible func type errors tested. Solution: Add more tests.
This commit is contained in:
@@ -442,6 +442,10 @@ def FuncOneArgRetNumber(arg: number): number
|
|||||||
return arg
|
return arg
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def FuncTwoArgNoRet(one: bool, two: number)
|
||||||
|
funcResult = two
|
||||||
|
enddef
|
||||||
|
|
||||||
def FuncOneArgRetString(arg: string): string
|
def FuncOneArgRetString(arg: string): string
|
||||||
return arg
|
return arg
|
||||||
enddef
|
enddef
|
||||||
@@ -511,6 +515,14 @@ def Test_func_type_fails()
|
|||||||
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncNoArgRetNumber'], 'E1013: type mismatch, expected func() but got func(): number')
|
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncNoArgRetNumber'], 'E1013: type mismatch, expected func() but got func(): number')
|
||||||
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgNoRet'], 'E1013: type mismatch, expected func() but got func(number)')
|
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgNoRet'], 'E1013: type mismatch, expected func() but got func(number)')
|
||||||
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1013: type mismatch, expected func() but got func(number): number')
|
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1013: type mismatch, expected func() but got func(number): number')
|
||||||
|
CheckDefFailure(['let Ref1: func(bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(bool) but got func(bool, number)')
|
||||||
|
CheckDefFailure(['let Ref1: func(?bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(?bool) but got func(bool, number)')
|
||||||
|
CheckDefFailure(['let Ref1: func(...bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: type mismatch, expected func(...bool) but got func(bool, number)')
|
||||||
|
|
||||||
|
call CheckDefFailure(['let RefWrong: func(string ,number)'], 'E1068:')
|
||||||
|
call CheckDefFailure(['let RefWrong: func(string,number)'], 'E1069:')
|
||||||
|
call CheckDefFailure(['let RefWrong: func(bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool)'], 'E740:')
|
||||||
|
call CheckDefFailure(['let RefWrong: func(bool):string'], 'E1069:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_func_return_type()
|
def Test_func_return_type()
|
||||||
|
@@ -738,6 +738,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 */
|
||||||
|
/**/
|
||||||
|
548,
|
||||||
/**/
|
/**/
|
||||||
547,
|
547,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1648,7 +1648,10 @@ parse_type(char_u **arg, garray_T *type_gap)
|
|||||||
{
|
{
|
||||||
++p;
|
++p;
|
||||||
if (!VIM_ISWHITE(*p))
|
if (!VIM_ISWHITE(*p))
|
||||||
|
{
|
||||||
semsg(_(e_white_after), ",");
|
semsg(_(e_white_after), ",");
|
||||||
|
return &t_any;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p = skipwhite(p);
|
p = skipwhite(p);
|
||||||
if (argcount == MAX_FUNC_ARGS)
|
if (argcount == MAX_FUNC_ARGS)
|
||||||
@@ -1675,7 +1678,7 @@ parse_type(char_u **arg, garray_T *type_gap)
|
|||||||
*arg = skipwhite(*arg);
|
*arg = skipwhite(*arg);
|
||||||
ret_type = parse_type(arg, type_gap);
|
ret_type = parse_type(arg, type_gap);
|
||||||
}
|
}
|
||||||
if (flags == 0 && first_optional == -1)
|
if (flags == 0 && first_optional == -1 && argcount <= 0)
|
||||||
type = get_func_type(ret_type, argcount, type_gap);
|
type = get_func_type(ret_type, argcount, type_gap);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1822,8 +1825,9 @@ vartype_name(vartype_T type)
|
|||||||
case VAR_CHANNEL: return "channel";
|
case VAR_CHANNEL: return "channel";
|
||||||
case VAR_LIST: return "list";
|
case VAR_LIST: return "list";
|
||||||
case VAR_DICT: return "dict";
|
case VAR_DICT: return "dict";
|
||||||
case VAR_FUNC: return "func";
|
|
||||||
case VAR_PARTIAL: return "partial";
|
case VAR_FUNC:
|
||||||
|
case VAR_PARTIAL: return "func";
|
||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
@@ -1853,7 +1857,7 @@ type_name(type_T *type, char **tofree)
|
|||||||
return *tofree;
|
return *tofree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type->tt_type == VAR_FUNC || type->tt_type == VAR_PARTIAL)
|
if (type->tt_type == VAR_FUNC)
|
||||||
{
|
{
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
int i;
|
int i;
|
||||||
@@ -1866,12 +1870,16 @@ type_name(type_T *type, char **tofree)
|
|||||||
STRCPY(ga.ga_data, "func(");
|
STRCPY(ga.ga_data, "func(");
|
||||||
ga.ga_len += 5;
|
ga.ga_len += 5;
|
||||||
|
|
||||||
for (i = 0; i < type->tt_argcount + varargs; ++i)
|
for (i = 0; i < type->tt_argcount; ++i)
|
||||||
{
|
{
|
||||||
char *arg_free;
|
char *arg_free;
|
||||||
char *arg_type = type_name(type->tt_args[i], &arg_free);
|
char *arg_type;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
if (type->tt_args == NULL)
|
||||||
|
arg_type = "[unknown]";
|
||||||
|
else
|
||||||
|
arg_type = type_name(type->tt_args[i], &arg_free);
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
STRCPY((char *)ga.ga_data + ga.ga_len, ", ");
|
STRCPY((char *)ga.ga_data + ga.ga_len, ", ");
|
||||||
@@ -1884,7 +1892,7 @@ type_name(type_T *type, char **tofree)
|
|||||||
return "[unknown]";
|
return "[unknown]";
|
||||||
}
|
}
|
||||||
*tofree = ga.ga_data;
|
*tofree = ga.ga_data;
|
||||||
if (i == type->tt_argcount)
|
if (varargs && i == type->tt_argcount - 1)
|
||||||
{
|
{
|
||||||
STRCPY((char *)ga.ga_data + ga.ga_len, "...");
|
STRCPY((char *)ga.ga_data + ga.ga_len, "...");
|
||||||
ga.ga_len += 3;
|
ga.ga_len += 3;
|
||||||
@@ -4007,8 +4015,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// new local variable
|
// new local variable
|
||||||
if ((type->tt_type == VAR_FUNC || type->tt_type == VAR_PARTIAL)
|
if (type->tt_type == VAR_FUNC && var_check_func_name(name, TRUE))
|
||||||
&& var_check_func_name(name, TRUE))
|
|
||||||
goto theend;
|
goto theend;
|
||||||
idx = reserve_local(cctx, arg, varlen, cmdidx == CMD_const, type);
|
idx = reserve_local(cctx, arg, varlen, cmdidx == CMD_const, type);
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
|
Reference in New Issue
Block a user