cgen: fix generic struct free() (#12487)
parent
11ce26b3f6
commit
927df948ae
|
@ -15,7 +15,7 @@ fn (mut g Gen) gen_free_method_for_type(typ ast.Type) string {
|
|||
}
|
||||
}
|
||||
|
||||
if sym.has_method('free') {
|
||||
if sym.has_method_with_generic_parent('free') {
|
||||
return fn_name
|
||||
}
|
||||
match mut sym.info {
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
struct List<T> {
|
||||
pub mut:
|
||||
head &ListNode<T> = 0
|
||||
}
|
||||
|
||||
struct ListNode<T> {
|
||||
pub mut:
|
||||
value T
|
||||
next &ListNode<T> = 0
|
||||
}
|
||||
|
||||
fn list_new<T>() List<T> {
|
||||
return List<T>{}
|
||||
}
|
||||
|
||||
fn listnode_new<T>() &ListNode<T> {
|
||||
return &ListNode<T>{0, 0}
|
||||
}
|
||||
|
||||
fn (mut l List<T>) free() {
|
||||
//
|
||||
}
|
||||
|
||||
fn test_generic_struct_free() {
|
||||
mut list := list_new<string>()
|
||||
println(list)
|
||||
list.free()
|
||||
assert true
|
||||
}
|
Loading…
Reference in New Issue