From abd0686043c1cdaa339dd3dfaf31101bbef88df1 Mon Sep 17 00:00:00 2001 From: Alexey Date: Sat, 4 Apr 2020 18:59:49 +0300 Subject: [PATCH] cgen: fix struct initialization --- vlib/v/gen/cgen.v | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index baa0f691c1..eff1e001b4 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -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))') } }