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:
parent
da090f91d8
commit
bf69d20353
@ -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 += '_'
|
||||
|
23
vlib/v/tests/generics_struct_anon_fn_type_test.v
Normal file
23
vlib/v/tests/generics_struct_anon_fn_type_test.v
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user