ast: fix error for 'struct embed is interface' (#13465)

pull/13466/head
yuyi 2022-02-14 19:43:36 +08:00 committed by GitHub
parent b2f984280b
commit 8119a297f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 1 deletions

View File

@ -1384,7 +1384,7 @@ pub fn (t Table) does_type_implement_interface(typ Type, inter_typ Type) bool {
}
// verify methods
for imethod in inter_sym.info.methods {
if method := sym.find_method(imethod.name) {
if method := t.find_method_with_embeds(sym, imethod.name) {
msg := t.is_same_method(imethod, method)
if msg.len > 0 {
return false

View File

@ -0,0 +1,53 @@
pub struct Base {
mut:
x int
y int
}
pub fn (mut b Base) init() {}
pub fn (b Base) get_pos() (int, int) {
return b.x, b.y
}
pub struct Label {
Base
}
pub interface Widget {
mut:
init()
}
pub interface Layoutable {
get_pos() (int, int)
}
pub struct Layout {
Base
mut:
widgets []Widget
}
pub fn (mut l Layout) layout() {
for wd in l.widgets {
if wd is Layoutable {
lw := wd as Layoutable
dump(lw.get_pos())
x, y := lw.get_pos()
assert x == 10
assert y == 20
} else {
println('wd is NOT Layoutable')
}
}
}
fn test_struct_embed_is_interface() {
mut l := Layout{}
l.widgets << Label{
x: 10
y: 20
}
l.layout()
}