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

parser: fix default optional value

This commit is contained in:
joe-conigliaro 2019-11-20 01:47:49 +11:00 committed by Alexander Medvednikov
parent ddcff7e9c5
commit 4bbed4f910

View File

@ -129,8 +129,10 @@ fn (p mut Parser) gen_handle_option_or_else(_typ, name string, fn_call_ph int) s
expr_line := p.cgen.lines[p.cgen.lines.len-2] expr_line := p.cgen.lines[p.cgen.lines.len-2]
last_expr := expr_line[last_ph..] last_expr := expr_line[last_ph..]
p.cgen.lines[p.cgen.lines.len-2] = '' p.cgen.lines[p.cgen.lines.len-2] = ''
p.genln('if (!${tmp}.ok) {') p.genln('if ($tmp .ok) {')
p.genln('$name = $last_expr;') p.genln('$name = *($typ*) $tmp . data;')
p.genln('} else {')
p.genln('$name = $last_expr')
p.genln('}') p.genln('}')
} else if is_assign { } else if is_assign {
p.genln('$name = *($typ*)${tmp}.data;') p.genln('$name = *($typ*)${tmp}.data;')