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

cgen: fix struct initialization

This commit is contained in:
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

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