cgen: fix generic struct free() (#12487)

pull/12505/head
yuyi 2021-11-17 13:18:46 +08:00 committed by GitHub
parent 11ce26b3f6
commit 927df948ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -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 {

View File

@ -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
}