1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix generic struct with anon fn parameter (#10147)

This commit is contained in:
yuyi 2021-05-20 21:57:27 +08:00 committed by GitHub
parent da090f91d8
commit bf69d20353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -618,7 +618,7 @@ fn (mut c Checker) unwrap_generics_struct_init(struct_type ast.Type) ast.Type {
for i in 0 .. ts.info.generic_types.len {
gts := c.table.get_type_symbol(c.unwrap_generic(ts.info.generic_types[i]))
nrt += gts.name
c_nrt += gts.name
c_nrt += gts.cname
if i != ts.info.generic_types.len - 1 {
nrt += ','
c_nrt += '_'
@ -1685,14 +1685,14 @@ fn (mut c Checker) check_return_generics_struct(return_type ast.Type, mut call_e
if rts.info is ast.Struct {
if rts.info.is_generic {
mut nrt := '$rts.name<'
mut c_nrt := '${rts.name}_T_'
mut c_nrt := '${rts.cname}_T_'
for i in 0 .. rts.info.generic_types.len {
if ct := c.table.resolve_generic_to_concrete(rts.info.generic_types[i],
generic_names, concrete_types, false)
{
gts := c.table.get_type_symbol(ct)
nrt += gts.name
c_nrt += gts.name
c_nrt += gts.cname
if i != rts.info.generic_types.len - 1 {
nrt += ','
c_nrt += '_'

View File

@ -0,0 +1,23 @@
fn neg(a int) int {
return -a
}
struct FnHolder<T> {
func T
}
fn (self FnHolder<T>) call<T>(a int) int {
return self.func(a)
}
fn holder_call<T>(func T, a int) int {
_ = FnHolder<T>{func}
return 0
}
fn test_generic_struct_with_anon_fn_parameter() {
mut ret := 0
ret = holder_call(neg, 1)
assert ret == 0
}