From 868d6c808ba61f26090928f2b8180eb34d9bf023 Mon Sep 17 00:00:00 2001 From: Ricardo Tomasi Date: Sun, 5 Jan 2020 11:53:40 +0100 Subject: [PATCH] compiler: avoid redeclaration of var during reassignment with optional value --- vlib/compiler/gen_c.v | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vlib/compiler/gen_c.v b/vlib/compiler/gen_c.v index dc8532e251..2e2a72d934 100644 --- a/vlib/compiler/gen_c.v +++ b/vlib/compiler/gen_c.v @@ -116,7 +116,7 @@ fn (p mut Parser) gen_handle_option_or_else(_typ, name string, fn_call_ph int) s is_mut: false is_used: true }) - if is_assign && !name.contains('.') { + if is_assign && !name.contains('.') && !p.is_var_decl { // don't initialize struct fields p.genln('$typ $name;') } @@ -717,4 +717,3 @@ fn (p mut Parser) gen_array_push(ph int, typ, expr_type, tmp, elm_type string) { p.gen('), $tmp, $elm_type)') } } -