cgen: fix zero init bug of embedded structs (#7567)

pull/7572/head
Daniel Däschle 2020-12-25 21:46:42 +01:00 committed by GitHub
parent 60086a06ac
commit 7507403118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -4460,6 +4460,9 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
// TODO handle/require optionals in inits
continue
}
if field.typ in info.embeds {
continue
}
g.zero_struct_field(field)
if is_multiline {
g.writeln(',')

View File

@ -26,6 +26,11 @@ fn test_default_value() {
b := Bar{Foo: Foo{}}
assert b.y == 5
}
fn test_default_value_without_init() {
b := Bar{}
assert b.y == 5
}
/* TODO
fn test_initialize() {
b := Bar{x: 1, y: 2}