patch 9.1.1629: Vim9: Not able to use more than 10 type arguments in a generic function
Problem: Vim9: Not able to use more than 10 type arguments in a generic
function
Solution: Initialize the types after reading all the type arg variable
names (Yegappan Lakshmanan)
closes: #17981
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
1ee1d9b43d
commit
706b6f5867
@ -3553,4 +3553,21 @@ def Test_generic_enum_constructor_error()
|
|||||||
v9.CheckSourceFailure(lines, "E1010: Type not recognized: A", 4)
|
v9.CheckSourceFailure(lines, "E1010: Type not recognized: A", 4)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
" Test for using more than 10 type arguments
|
||||||
|
def Test_generic_max_type_args()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
def Fn<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12>(a1: A1): A1
|
||||||
|
var x: A1 = a1
|
||||||
|
return x
|
||||||
|
enddef
|
||||||
|
|
||||||
|
assert_equal(10, Fn<number, string, string, string, string, string, string, string, string, string, string, string>(10))
|
||||||
|
|
||||||
|
assert_equal('abc', Fn<string, number, number, number, number, number, number, number, number, number, number, number>('abc'))
|
||||||
|
END
|
||||||
|
v9.CheckSourceSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
||||||
|
|||||||
@ -719,6 +719,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 */
|
||||||
|
/**/
|
||||||
|
1629,
|
||||||
/**/
|
/**/
|
||||||
1628,
|
1628,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
@ -526,16 +526,6 @@ parse_generic_func_type_params(
|
|||||||
if (name_exists)
|
if (name_exists)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (ga_grow(&gfatab->gfat_param_types, 1) == FAIL)
|
|
||||||
return NULL;
|
|
||||||
type_T *gt =
|
|
||||||
&((type_T *)gfatab->gfat_param_types.ga_data)[gfatab->gfat_param_types.ga_len];
|
|
||||||
gfatab->gfat_param_types.ga_len++;
|
|
||||||
|
|
||||||
CLEAR_POINTER(gt);
|
|
||||||
gt->tt_type = VAR_ANY;
|
|
||||||
gt->tt_flags = TTFLAG_GENERIC;
|
|
||||||
|
|
||||||
if (ga_grow(&gfatab->gfat_args, 1) == FAIL)
|
if (ga_grow(&gfatab->gfat_args, 1) == FAIL)
|
||||||
return NULL;
|
return NULL;
|
||||||
generic_T *generic =
|
generic_T *generic =
|
||||||
@ -546,7 +536,7 @@ parse_generic_func_type_params(
|
|||||||
if (generic->gt_name == NULL)
|
if (generic->gt_name == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
vim_strncpy(generic->gt_name, name_start, name_len);
|
vim_strncpy(generic->gt_name, name_start, name_len);
|
||||||
generic->gt_type = gt;
|
generic->gt_type = NULL;
|
||||||
|
|
||||||
if (VIM_ISWHITE(*p))
|
if (VIM_ISWHITE(*p))
|
||||||
{
|
{
|
||||||
@ -572,13 +562,32 @@ parse_generic_func_type_params(
|
|||||||
}
|
}
|
||||||
if (*p != '>')
|
if (*p != '>')
|
||||||
return NULL;
|
return NULL;
|
||||||
|
p++;
|
||||||
|
|
||||||
if (generic_func_args_table_size(gfatab) == 0)
|
int gfat_sz = generic_func_args_table_size(gfatab);
|
||||||
|
|
||||||
|
if (gfat_sz == 0)
|
||||||
{
|
{
|
||||||
emsg_funcname(e_empty_type_list_for_generic_function_str, func_name);
|
emsg_funcname(e_empty_type_list_for_generic_function_str, func_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
p++;
|
|
||||||
|
// set the generic parms to VAR_ANY type
|
||||||
|
if (ga_grow(&gfatab->gfat_param_types, gfat_sz) == FAIL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
gfatab->gfat_param_types.ga_len = gfat_sz;
|
||||||
|
for (int i = 0; i < generic_func_args_table_size(gfatab); i++)
|
||||||
|
{
|
||||||
|
type_T *gt = &((type_T *)gfatab->gfat_param_types.ga_data)[i];
|
||||||
|
|
||||||
|
CLEAR_POINTER(gt);
|
||||||
|
gt->tt_type = VAR_ANY;
|
||||||
|
gt->tt_flags = TTFLAG_GENERIC;
|
||||||
|
|
||||||
|
generic_T *generic = &((generic_T *)gfatab->gfat_args.ga_data)[i];
|
||||||
|
generic->gt_type = gt;
|
||||||
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user