cgen: fix interface embedding complex cases (#13472)

pull/13479/head
yuyi 2022-02-15 18:41:40 +08:00 committed by GitHub
parent 73cf597bec
commit fb3dd82400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 1 deletions

View File

@ -5536,7 +5536,7 @@ static inline __shared__$interface_name ${shared_fn_name}(__shared__$cctype* x)
}
t_methods := g.table.get_embed_methods(st_sym)
for t_method in t_methods {
if t_method.name !in method_names {
if t_method.name !in methods.map(it.name) {
methods << t_method
}
}

View File

@ -0,0 +1,57 @@
fn test_interface_embedding_complex() {
mut win := &Window{}
ll := &LinearLayout{}
win.initables << ll
win.init()
}
//----------------------------------
[heap]
pub struct Window {
mut:
initables []Initable
}
interface Initable {
get_ptr()
mut:
init(&Window)
}
fn (mut w Window) init() {
for mut i in w.initables {
i.init(w)
}
}
//----------------------------------
pub struct ViewBase {}
pub fn (mut vb ViewBase) init(window &Window) {
dump(@METHOD)
assert false
}
pub fn (vb ViewBase) get_ptr() {}
//-------------------------------------
[heap]
pub struct ContainerBase {
ViewBase
}
// want to excute this method
pub fn (mut cb ContainerBase) init(window &Window) {
dump(@METHOD)
assert true
}
//--------------------------------------
[heap]
pub struct LinearLayout {
ContainerBase
}