cgen: fix multiple nested embed struct with duplicate field init (#12805)

pull/12814/head
yuyi 2021-12-13 01:54:29 +08:00 committed by GitHub
parent f407d6de02
commit 57c1faadbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -6023,6 +6023,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
default_init := ast.StructInit{
...struct_init
typ: embed
fields: init_fields_to_embed
}
g.write('.$embed_name = ')
g.struct_init(default_init)

View File

@ -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
}