cgen: fix ci error of empty struct init (#12838)

pull/12841/head
yuyi 2021-12-15 14:49:30 +08:00 committed by GitHub
parent 6079448f35
commit 1c629f4a93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -6816,7 +6816,15 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
}
init_str += '.$field_name = $expr_str,'
} else {
zero_str := g.type_default(field.typ)
mut zero_str := g.type_default(field.typ)
if zero_str == '{0}' {
if field_sym.info is ast.Struct && field_sym.language == .v {
if field_sym.info.fields.len == 0
&& field_sym.info.embeds.len == 0 {
zero_str = '{EMPTY_STRUCT_INITIALIZATION}'
}
}
}
init_str += '.$field_name = $zero_str,'
}
has_none_zero = true