1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix empty struct init (#9769)

This commit is contained in:
yuyi 2021-04-17 07:39:52 +08:00 committed by GitHub
parent 0a1d0e062d
commit 0cc04850d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5122,9 +5122,12 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
} }
// The rest of the fields are zeroed. // The rest of the fields are zeroed.
// `inited_fields` is a list of fields that have been init'ed, they are skipped // `inited_fields` is a list of fields that have been init'ed, they are skipped
// mut nr_fields := 0 mut nr_fields := 1
if sym.kind == .struct_ { if sym.kind == .struct_ {
info := sym.info as ast.Struct info := sym.info as ast.Struct
$if !msvc {
nr_fields = info.fields.len
}
if info.is_union && struct_init.fields.len > 1 { if info.is_union && struct_init.fields.len > 1 {
verror('union must not have more than 1 initializer') verror('union must not have more than 1 initializer')
} }
@ -5219,7 +5222,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
g.indent-- g.indent--
} }
if !initialized { if !initialized && nr_fields > 0 {
g.write('0') g.write('0')
} }