cgen: clone strings in struct_init()

pull/4788/head
Alexander Medvednikov 2020-05-08 15:07:50 +02:00
parent ef505e21ee
commit c29f76454e
1 changed files with 11 additions and 6 deletions

View File

@ -2162,12 +2162,17 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
field_name := c_name(field.name)
inited_fields << field.name
g.write('\t.$field_name = ')
// if g.autofree && right_sym.kind in [.array, .string] {
// g.write('/*clone1*/')
// if g.gen_clone_assignment(field.expr, right_sym, true) {
// }
// }
field_type_sym := g.table.get_type_symbol(field.typ)
mut cloned := false
if g.autofree && field_type_sym.kind in [.array, .string] {
g.write('/*clone1*/')
if g.gen_clone_assignment(field.expr, field_type_sym, false) {
cloned = true
}
}
if !cloned {
g.expr_with_cast(field.expr, field.typ, field.expected_type)
}
g.writeln(',')
}
// The rest of the fields are zeroed.