cgen: fix multiple embed struct init (#12791)

pull/12793/head
yuyi 2021-12-11 15:28:32 +08:00 committed by GitHub
parent eaf0f9b4c1
commit ade2a4cd01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -6020,8 +6020,8 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
&& it.name in embed_field_names)
used_embed_fields << fields_to_embed.map(it.name)
default_init := ast.StructInit{
...struct_init
typ: embed
fields: fields_to_embed
}
g.write('.$embed_name = ')
g.struct_init(default_init)

View File

@ -0,0 +1,31 @@
pub struct Boundary {
mut:
x int
y int
offset_x int
offset_y int
width int
height int
}
pub struct WidgetBase {
Boundary
mut:
id string
z_index int
hidden bool
}
pub struct Label {
WidgetBase
}
fn test_multiple_embed_struct_init() {
l := Label{
x: 100
y: 200
}
println(l)
assert l.x == 100
assert l.y == 200
}