Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ast: fix error for struct embedding with interface (#13457)
- Loading branch information
Showing
2 changed files
with
60 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 '' | ||
} |