cgen: fix multiple nested embed struct with duplicate field init (#12805)
parent
f407d6de02
commit
57c1faadbe
|
@ -6023,6 +6023,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
|
||||||
default_init := ast.StructInit{
|
default_init := ast.StructInit{
|
||||||
...struct_init
|
...struct_init
|
||||||
typ: embed
|
typ: embed
|
||||||
|
fields: init_fields_to_embed
|
||||||
}
|
}
|
||||||
g.write('.$embed_name = ')
|
g.write('.$embed_name = ')
|
||||||
g.struct_init(default_init)
|
g.struct_init(default_init)
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
struct Foo {
|
||||||
|
mut:
|
||||||
|
x int
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
Foo
|
||||||
|
mut:
|
||||||
|
x int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_multiple_embed_struct_with_duplicate_field_init() {
|
||||||
|
mut b := Bar{
|
||||||
|
x: 2
|
||||||
|
}
|
||||||
|
println(b)
|
||||||
|
assert b.x == 2
|
||||||
|
assert b.Foo.x == 0
|
||||||
|
}
|
Loading…
Reference in New Issue