cgen: fix error of method calls on nested embedded structs (#13292)
parent
f8f7bc8ead
commit
9dce8194a8
|
@ -1047,10 +1047,15 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
|||
} else {
|
||||
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_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('->')
|
||||
} else {
|
||||
g.write('.')
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue