cgen: fix struct initialization

pull/4240/head
Alexey 2020-04-04 18:59:49 +03:00 committed by GitHub
parent bb587c27a8
commit abd0686043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -1902,7 +1902,8 @@ fn (g mut Gen) struct_init(it ast.StructInit) {
// info := g.table.get_type_symbol(it.typ).info as table.Struct
// println(info.fields.len)
styp := g.typ(it.typ)
if g.is_amp {
is_amp := g.is_amp
if is_amp {
g.out.go_back(1) // delete the & already generated in `prefix_expr()
g.write('($styp*)memdup(&($styp){')
}
@ -1943,7 +1944,7 @@ fn (g mut Gen) struct_init(it ast.StructInit) {
g.write('0')
}
g.write('}')
if g.is_amp {
if is_amp {
g.write(', sizeof($styp))')
}
}