From 4794598d06fa948d4abc7c4c28aaf5c16118e83a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 1 Jan 2020 10:31:50 +0100 Subject: [PATCH] if x := opt() {} else {} --- vlib/compiler/if_match.v | 6 ++++++ vlib/v/parser/parser.v | 33 +++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/vlib/compiler/if_match.v b/vlib/compiler/if_match.v index b74481de8e..b17a386506 100644 --- a/vlib/compiler/if_match.v +++ b/vlib/compiler/if_match.v @@ -265,6 +265,12 @@ fn (p mut Parser) if_statement(is_expr bool, elif_depth int) string { p.statements() p.close_scope() p.returns = false + if p.tok == .key_else { + p.next() + p.genln('else {') + p.check(.lcbr) + p.statements() + } return 'void' } else { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 71ae29ab33..413fee4a23 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -265,27 +265,28 @@ pub fn (p &Parser) warn(s string) { pub fn (p mut Parser) call_expr() (ast.CallExpr,types.Type) { // println('got fn call') - fn_name := p.tok.lit - f := p.table.find_fn(fn_name) or { - p.error('unknown function `$p.tok.lit`') - exit(0) - } - p.check(.name) + fn_name := p.check_name() p.check(.lpar) mut args := []ast.Expr - for i, arg in f.args { - e,typ := p.expr(0) - if !types.check(arg.typ, typ) { - p.error('cannot used type `$typ.name` as type `$arg.typ.name` in argument to `$fn_name`') + if f := p.table.find_fn(fn_name) { + for i, arg in f.args { + e,typ := p.expr(0) + if !types.check(arg.typ, typ) { + p.error('cannot use type `$typ.name` as type `$arg.typ.name` in argument to `$fn_name`') + } + args << e + if i < f.args.len - 1 { + p.check(.comma) + } } - args << e - if i < f.args.len - 1 { - p.check(.comma) + if p.tok.kind == .comma { + p.error('too many arguments in call to `$fn_name`') } } - if p.tok.kind == .comma { - p.error('too many arguments in call to `$fn_name`') - } + // else{ + // p.error('unknown function `$fn_name`') + // } + // exit(0) p.check(.rpar) node := ast.CallExpr{ name: fn_name