checker: fix generic struct with anon fn parameter (#10147)
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 {
|
for i in 0 .. ts.info.generic_types.len {
|
||||||
gts := c.table.get_type_symbol(c.unwrap_generic(ts.info.generic_types[i]))
|
gts := c.table.get_type_symbol(c.unwrap_generic(ts.info.generic_types[i]))
|
||||||
nrt += gts.name
|
nrt += gts.name
|
||||||
c_nrt += gts.name
|
c_nrt += gts.cname
|
||||||
if i != ts.info.generic_types.len - 1 {
|
if i != ts.info.generic_types.len - 1 {
|
||||||
nrt += ','
|
nrt += ','
|
||||||
c_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 ast.Struct {
|
||||||
if rts.info.is_generic {
|
if rts.info.is_generic {
|
||||||
mut nrt := '$rts.name<'
|
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 {
|
for i in 0 .. rts.info.generic_types.len {
|
||||||
if ct := c.table.resolve_generic_to_concrete(rts.info.generic_types[i],
|
if ct := c.table.resolve_generic_to_concrete(rts.info.generic_types[i],
|
||||||
generic_names, concrete_types, false)
|
generic_names, concrete_types, false)
|
||||||
{
|
{
|
||||||
gts := c.table.get_type_symbol(ct)
|
gts := c.table.get_type_symbol(ct)
|
||||||
nrt += gts.name
|
nrt += gts.name
|
||||||
c_nrt += gts.name
|
c_nrt += gts.cname
|
||||||
if i != rts.info.generic_types.len - 1 {
|
if i != rts.info.generic_types.len - 1 {
|
||||||
nrt += ','
|
nrt += ','
|
||||||
c_nrt += '_'
|
c_nrt += '_'
|
||||||
|
|
|
@ -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