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

foo()? syntax

This commit is contained in:
Alexander Medvednikov
2019-11-13 21:47:05 +03:00
parent 72249ce889
commit b1fa0d25f0
5 changed files with 34 additions and 10 deletions

View File

@ -129,11 +129,11 @@ 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]
last_expr := expr_line[last_ph..]
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('}')
} else if is_assign {
p.genln('$name = *($typ*) $tmp . data;')
p.genln('$name = *($typ*)${tmp}.data;')
}
if !p.returns && last_typ != typ && is_assign && p.prev_tok2 != .key_continue && p.prev_tok2 != .key_break {
p.error_with_token_index('`or` block must provide a default value or return/exit/continue/break/panic', or_tok_idx)