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

parser: make p.opt()? work for methods

This commit is contained in:
ʇʞʌp
2019-11-25 22:04:59 -08:00
committed by Alexander Medvednikov
parent 385c045e5a
commit 79a02a4c09
3 changed files with 21 additions and 12 deletions

View File

@ -329,17 +329,7 @@ fn (p mut Parser) name_expr() string {
is_or_else := p.tok == .key_orelse
if p.tok == .question {
// `files := os.ls('.')?`
if p.cur_fn.name != 'main__main' {
p.error('`func()?` syntax can only be used inside `fn main()` for now')
}
p.next()
tmp := p.get_tmp()
p.cgen.set_placeholder(fn_call_ph, '$f.typ $tmp = ')
p.genln(';')
p.genln('if (!${tmp}.ok) v_panic(${tmp}.error);')
typ := f.typ[7..] // option_xxx
p.gen('*($typ*) ${tmp}.data;')
return typ
return p.gen_handle_question_suffix(f, fn_call_ph)
}
else if !p.is_var_decl && is_or_else {
f.typ = p.gen_handle_option_or_else(f.typ, '', fn_call_ph)