Skip to content

Commit

Permalink
ast: fix error for struct embedding with interface (#13457)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Feb 14, 2022
1 parent bf11df4 commit 2e0f8ee
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
7 changes: 0 additions & 7 deletions vlib/v/ast/table.v
Expand Up @@ -1293,14 +1293,7 @@ pub fn (mut t Table) complete_interface_check() {
if tsym.kind != .struct_ {
continue
}
info := tsym.info as Struct
for _, mut idecl in t.interfaces {
if idecl.methods.len > tsym.methods.len {
continue
}
if idecl.fields.len > info.fields.len {
continue
}
if idecl.typ == 0 {
continue
}
Expand Down
60 changes: 60 additions & 0 deletions vlib/v/tests/struct_embedding_with_interface_test.v
@@ -0,0 +1,60 @@
fn test_struct_embedding_with_interface() {
mut ll := LinearLayout{}
mut lv := ListView{}
ll.add(lv)
ret := ll.layout()

println(ret)
assert ret.count('ListView') == 2
}

interface Container {
mut:
layout() string
}

interface Layoutable {
get_pos() (int, int)
mut:
set_pos(int, int)
}

pub struct LayouterBase {
mut:
layoutables []Layoutable
}

pub fn (mut lb LayouterBase) add(layoutable Layoutable) {
lb.layoutables << layoutable
}

pub fn (lb LayouterBase) get_pos() (int, int) {
return 0, 0
}

pub fn (mut lb LayouterBase) set_pos(x int, y int) {}

pub struct LinearLayout {
LayouterBase
}

pub fn (mut ll LinearLayout) layout() string {
mut output := ''
for mut l in ll.layoutables {
dump(l.type_name())
output += '$l.type_name()\n'
if l is Container {
dump(l.type_name())
output += '$l.type_name()\n'
}
}
return output
}

pub struct ListView {
LayouterBase
}

pub fn (mut lv ListView) layout() string {
return ''
}

0 comments on commit 2e0f8ee

Please sign in to comment.