patch 9.2.1217: Vim9: varargs type of generic function not in function type
Problem: Vim9: when a generic function with variable arguments is used
with type arguments, the type variable in the variable arguments
type is not replaced in the function type, e.g. it is
"func(...list<any>)" instead of "func(...list<number>)".
Solution: Also replace the type variable in the function type
(Yegappan Lakshmanan).
fixes: #21568
closes: #21507
Assisted-by: Claude
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
1 parent
9c32169e1d
commit
b79efe0f40
3 files changed
+34
-2
No files matched your search
@@ -3988,6 +3988,29 @@ def Test_generic_type_var_name_prefix()
|
||||
v9.CheckSourceFailure(lines, 'E1010: Type not recognized: T', 2)
|
||||
enddef
|
||||
|
||||
" Test for the function type of a generic function with variable arguments
|
||||
def Test_generic_func_varargs_type()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
def Fn<T>(...l: list<T>): list<T>
|
||||
return l
|
||||
enddef
|
||||
assert_equal('func(...list<number>): list<number>', typename(Fn<number>))
|
||||
var F: func(...list<number>): list<number> = Fn<number>
|
||||
assert_equal([1, 2], F(1, 2))
|
||||
END
|
||||
v9.CheckSourceSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
def Fn<T>(...l: list<T>): list<T>
|
||||
return l
|
||||
enddef
|
||||
var F: func(...list<string>): list<number> = Fn<number>
|
||||
END
|
||||
v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(...list<string>): list<number> but got func(...list<number>): list<number>', 5)
|
||||
enddef
|
||||
|
||||
" Test for using a generic method to initialize an object member variable
|
||||
def Test_generic_method_in_object_member_init_expr()
|
||||
var lines =<< trim END
|
||||
|
||||
@@ -743,6 +743,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1217,
|
||||
/**/
|
||||
1216,
|
||||
/**/
|
||||
|
||||
+9
-2
@@ -918,10 +918,17 @@ generic_func_copy_types(ufunc_T *fp, ufunc_T *new_fp)
|
||||
&& ft->tt_argcount > i
|
||||
? &ft->tt_args[i] : NULL);
|
||||
|
||||
// Update the vararg type if it uses generic types
|
||||
// Update the vararg type if it uses generic types. It is the last
|
||||
// argument of the function type.
|
||||
if (fp->uf_va_type != NULL)
|
||||
{
|
||||
int va_idx = fp->uf_args.ga_len;
|
||||
|
||||
update_generic_type(fp, new_fp, fp->uf_va_type, &new_fp->uf_va_type,
|
||||
NULL);
|
||||
ft != NULL && ft->tt_args != NULL
|
||||
&& ft->tt_argcount > va_idx
|
||||
? &ft->tt_args[va_idx] : NULL);
|
||||
}
|
||||
|
||||
// Update the return type if it is a generic type
|
||||
if (fp->uf_ret_type != NULL)
|
||||
|
||||
Reference in new issue
Block a user