mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix multiple embed struct init (#12791)
This commit is contained in:
parent
eaf0f9b4c1
commit
ade2a4cd01
@ -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)
|
||||
|
31
vlib/v/tests/multiple_embed_struct_init_test.v
Normal file
31
vlib/v/tests/multiple_embed_struct_init_test.v
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user