cgen: fix error of method calls on nested embedded structs (#13292)

pull/13294/head
yuyi 2022-01-27 19:20:56 +08:00 committed by GitHub
parent f8f7bc8ead
commit 9dce8194a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 2 deletions

View File

@ -1047,10 +1047,15 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
} else { } else {
g.expr(node.left) g.expr(node.left)
} }
for embed in node.from_embed_types { for i, embed in node.from_embed_types {
embed_sym := g.table.sym(embed) embed_sym := g.table.sym(embed)
embed_name := embed_sym.embed_name() embed_name := embed_sym.embed_name()
if node.left_type.is_ptr() { is_left_ptr := if i == 0 {
node.left_type.is_ptr()
} else {
node.from_embed_types[i - 1].is_ptr()
}
if is_left_ptr {
g.write('->') g.write('->')
} else { } else {
g.write('.') g.write('.')

View File

@ -0,0 +1,33 @@
pub struct Boundary {}
pub fn (b Boundary) contains(x int, y int) bool {
return false
}
pub struct Base {
Boundary
}
pub fn (mut b Base) on_event(x int, y int) {
if b.Boundary.contains(x, y) {
}
if b.contains(x, y) {
}
}
pub struct ListBox {
Base
}
pub fn (mut lb ListBox) on_event(x int, y int) {
if lb.Base.Boundary.contains(x, y) {
}
if lb.contains(x, y) {
}
}
fn test_struct_multi_embed_method_call() {
mut list_box := ListBox{}
list_box.on_event(11, 22)
assert true
}