forked from aniani/vim
patch 8.2.5026: Vim9: a few lines not covered by tests
Problem: Vim9: a few lines not covered by tests. Solution: Delete dead code. Add a few test cases. make "12->func()" work.
This commit is contained in:
@@ -244,48 +244,44 @@ alloc_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
|
||||
|
||||
/*
|
||||
* Get a function type, based on the return type "ret_type".
|
||||
* If "argcount" is -1 or 0 a predefined type can be used.
|
||||
* If "argcount" > 0 always create a new type, so that arguments can be added.
|
||||
* "argcount" must be -1 or 0, a predefined type can be used.
|
||||
*/
|
||||
type_T *
|
||||
get_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
|
||||
{
|
||||
// recognize commonly used types
|
||||
if (argcount <= 0)
|
||||
if (ret_type == &t_unknown || ret_type == NULL)
|
||||
{
|
||||
if (ret_type == &t_unknown || ret_type == NULL)
|
||||
{
|
||||
// (argcount == 0) is not possible
|
||||
return &t_func_unknown;
|
||||
}
|
||||
if (ret_type == &t_void)
|
||||
{
|
||||
if (argcount == 0)
|
||||
return &t_func_0_void;
|
||||
else
|
||||
return &t_func_void;
|
||||
}
|
||||
if (ret_type == &t_any)
|
||||
{
|
||||
if (argcount == 0)
|
||||
return &t_func_0_any;
|
||||
else
|
||||
return &t_func_any;
|
||||
}
|
||||
if (ret_type == &t_number)
|
||||
{
|
||||
if (argcount == 0)
|
||||
return &t_func_0_number;
|
||||
else
|
||||
return &t_func_number;
|
||||
}
|
||||
if (ret_type == &t_string)
|
||||
{
|
||||
if (argcount == 0)
|
||||
return &t_func_0_string;
|
||||
else
|
||||
return &t_func_string;
|
||||
}
|
||||
// (argcount == 0) is not possible
|
||||
return &t_func_unknown;
|
||||
}
|
||||
if (ret_type == &t_void)
|
||||
{
|
||||
if (argcount == 0)
|
||||
return &t_func_0_void;
|
||||
else
|
||||
return &t_func_void;
|
||||
}
|
||||
if (ret_type == &t_any)
|
||||
{
|
||||
if (argcount == 0)
|
||||
return &t_func_0_any;
|
||||
else
|
||||
return &t_func_any;
|
||||
}
|
||||
if (ret_type == &t_number)
|
||||
{
|
||||
if (argcount == 0)
|
||||
return &t_func_0_number;
|
||||
else
|
||||
return &t_func_number;
|
||||
}
|
||||
if (ret_type == &t_string)
|
||||
{
|
||||
if (argcount == 0)
|
||||
return &t_func_0_string;
|
||||
else
|
||||
return &t_func_string;
|
||||
}
|
||||
|
||||
return alloc_func_type(ret_type, argcount, type_gap);
|
||||
@@ -541,7 +537,7 @@ typval2type_vimvar(typval_T *tv, garray_T *type_gap)
|
||||
{
|
||||
if (tv->v_type == VAR_LIST) // e.g. for v:oldfiles
|
||||
return &t_list_string;
|
||||
if (tv->v_type == VAR_DICT) // e.g. for v:completed_item
|
||||
if (tv->v_type == VAR_DICT) // e.g. for v:event
|
||||
return &t_dict_any;
|
||||
return typval2type(tv, get_copyID(), type_gap, TVTT_DO_MEMBER);
|
||||
}
|
||||
@@ -1441,6 +1437,7 @@ vartype_name(vartype_T type)
|
||||
type_name(type_T *type, char **tofree)
|
||||
{
|
||||
char *name;
|
||||
char *arg_free = NULL;
|
||||
|
||||
*tofree = NULL;
|
||||
if (type == NULL)
|
||||
@@ -1469,13 +1466,12 @@ type_name(type_T *type, char **tofree)
|
||||
|
||||
ga_init2(&ga, 1, 100);
|
||||
if (ga_grow(&ga, 20) == FAIL)
|
||||
return "[unknown]";
|
||||
goto failed;
|
||||
STRCPY(ga.ga_data, "func(");
|
||||
ga.ga_len += 5;
|
||||
|
||||
for (i = 0; i < type->tt_argcount; ++i)
|
||||
{
|
||||
char *arg_free = NULL;
|
||||
char *arg_type;
|
||||
int len;
|
||||
|
||||
@@ -1490,17 +1486,13 @@ type_name(type_T *type, char **tofree)
|
||||
}
|
||||
len = (int)STRLEN(arg_type);
|
||||
if (ga_grow(&ga, len + 8) == FAIL)
|
||||
{
|
||||
vim_free(arg_free);
|
||||
ga_clear(&ga);
|
||||
return "[unknown]";
|
||||
}
|
||||
goto failed;
|
||||
if (varargs && i == type->tt_argcount - 1)
|
||||
ga_concat(&ga, (char_u *)"...");
|
||||
else if (i >= type->tt_min_argcount)
|
||||
*((char *)ga.ga_data + ga.ga_len++) = '?';
|
||||
ga_concat(&ga, (char_u *)arg_type);
|
||||
vim_free(arg_free);
|
||||
VIM_CLEAR(arg_free);
|
||||
}
|
||||
if (type->tt_argcount < 0)
|
||||
// any number of arguments
|
||||
@@ -1516,17 +1508,18 @@ type_name(type_T *type, char **tofree)
|
||||
|
||||
len = (int)STRLEN(ret_name) + 4;
|
||||
if (ga_grow(&ga, len) == FAIL)
|
||||
{
|
||||
vim_free(ret_free);
|
||||
ga_clear(&ga);
|
||||
return "[unknown]";
|
||||
}
|
||||
goto failed;
|
||||
STRCPY((char *)ga.ga_data + ga.ga_len, "): ");
|
||||
STRCPY((char *)ga.ga_data + ga.ga_len + 3, ret_name);
|
||||
vim_free(ret_free);
|
||||
}
|
||||
*tofree = ga.ga_data;
|
||||
return ga.ga_data;
|
||||
|
||||
failed:
|
||||
vim_free(arg_free);
|
||||
ga_clear(&ga);
|
||||
return "[unknown]";
|
||||
}
|
||||
|
||||
return name;
|
||||
|
Reference in New Issue
Block a user