cgen: fix multiple embed struct init (#12791)
parent
eaf0f9b4c1
commit
ade2a4cd01
|
@ -6020,8 +6020,8 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
|
||||||
&& it.name in embed_field_names)
|
&& it.name in embed_field_names)
|
||||||
used_embed_fields << fields_to_embed.map(it.name)
|
used_embed_fields << fields_to_embed.map(it.name)
|
||||||
default_init := ast.StructInit{
|
default_init := ast.StructInit{
|
||||||
|
...struct_init
|
||||||
typ: embed
|
typ: embed
|
||||||
fields: fields_to_embed
|
|
||||||
}
|
}
|
||||||
g.write('.$embed_name = ')
|
g.write('.$embed_name = ')
|
||||||
g.struct_init(default_init)
|
g.struct_init(default_init)
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue