Skip to content

Commit 706b6f5

Browse files
yegappanchrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 1ee1d9b commit 706b6f5

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

src/testdir/test_vim9_generics.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,4 +3553,21 @@ def Test_generic_enum_constructor_error()
35533553
v9.CheckSourceFailure(lines, "E1010: Type not recognized: A", 4)
35543554
enddef
35553555

3556+
" Test for using more than 10 type arguments
3557+
def Test_generic_max_type_args()
3558+
var lines =<< trim END
3559+
vim9script
3560+
3561+
def Fn<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12>(a1: A1): A1
3562+
var x: A1 = a1
3563+
return x
3564+
enddef
3565+
3566+
assert_equal(10, Fn<number, string, string, string, string, string, string, string, string, string, string, string>(10))
3567+
3568+
assert_equal('abc', Fn<string, number, number, number, number, number, number, number, number, number, number, number>('abc'))
3569+
END
3570+
v9.CheckSourceSuccess(lines)
3571+
enddef
3572+
35563573
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static char *(features[]) =
719719

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
1629,
722724
/**/
723725
1628,
724726
/**/

src/vim9generics.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,6 @@ parse_generic_func_type_params(
526526
if (name_exists)
527527
return NULL;
528528

529-
if (ga_grow(&gfatab->gfat_param_types, 1) == FAIL)
530-
return NULL;
531-
type_T *gt =
532-
&((type_T *)gfatab->gfat_param_types.ga_data)[gfatab->gfat_param_types.ga_len];
533-
gfatab->gfat_param_types.ga_len++;
534-
535-
CLEAR_POINTER(gt);
536-
gt->tt_type = VAR_ANY;
537-
gt->tt_flags = TTFLAG_GENERIC;
538-
539529
if (ga_grow(&gfatab->gfat_args, 1) == FAIL)
540530
return NULL;
541531
generic_T *generic =
@@ -546,7 +536,7 @@ parse_generic_func_type_params(
546536
if (generic->gt_name == NULL)
547537
return NULL;
548538
vim_strncpy(generic->gt_name, name_start, name_len);
549-
generic->gt_type = gt;
539+
generic->gt_type = NULL;
550540

551541
if (VIM_ISWHITE(*p))
552542
{
@@ -572,13 +562,32 @@ parse_generic_func_type_params(
572562
}
573563
if (*p != '>')
574564
return NULL;
565+
p++;
575566

576-
if (generic_func_args_table_size(gfatab) == 0)
567+
int gfat_sz = generic_func_args_table_size(gfatab);
568+
569+
if (gfat_sz == 0)
577570
{
578571
emsg_funcname(e_empty_type_list_for_generic_function_str, func_name);
579572
return NULL;
580573
}
581-
p++;
574+
575+
// set the generic parms to VAR_ANY type
576+
if (ga_grow(&gfatab->gfat_param_types, gfat_sz) == FAIL)
577+
return NULL;
578+
579+
gfatab->gfat_param_types.ga_len = gfat_sz;
580+
for (int i = 0; i < generic_func_args_table_size(gfatab); i++)
581+
{
582+
type_T *gt = &((type_T *)gfatab->gfat_param_types.ga_data)[i];
583+
584+
CLEAR_POINTER(gt);
585+
gt->tt_type = VAR_ANY;
586+
gt->tt_flags = TTFLAG_GENERIC;
587+
588+
generic_T *generic = &((generic_T *)gfatab->gfat_args.ga_data)[i];
589+
generic->gt_type = gt;
590+
}
582591

583592
return p;
584593
}

0 commit comments

Comments
 (0)