if x := opt() {} else {}
parent
96d02849aa
commit
4794598d06
|
@ -265,6 +265,12 @@ fn (p mut Parser) if_statement(is_expr bool, elif_depth int) string {
|
||||||
p.statements()
|
p.statements()
|
||||||
p.close_scope()
|
p.close_scope()
|
||||||
p.returns = false
|
p.returns = false
|
||||||
|
if p.tok == .key_else {
|
||||||
|
p.next()
|
||||||
|
p.genln('else {')
|
||||||
|
p.check(.lcbr)
|
||||||
|
p.statements()
|
||||||
|
}
|
||||||
return 'void'
|
return 'void'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -265,27 +265,28 @@ pub fn (p &Parser) warn(s string) {
|
||||||
|
|
||||||
pub fn (p mut Parser) call_expr() (ast.CallExpr,types.Type) {
|
pub fn (p mut Parser) call_expr() (ast.CallExpr,types.Type) {
|
||||||
// println('got fn call')
|
// println('got fn call')
|
||||||
fn_name := p.tok.lit
|
fn_name := p.check_name()
|
||||||
f := p.table.find_fn(fn_name) or {
|
|
||||||
p.error('unknown function `$p.tok.lit`')
|
|
||||||
exit(0)
|
|
||||||
}
|
|
||||||
p.check(.name)
|
|
||||||
p.check(.lpar)
|
p.check(.lpar)
|
||||||
mut args := []ast.Expr
|
mut args := []ast.Expr
|
||||||
for i, arg in f.args {
|
if f := p.table.find_fn(fn_name) {
|
||||||
e,typ := p.expr(0)
|
for i, arg in f.args {
|
||||||
if !types.check(arg.typ, typ) {
|
e,typ := p.expr(0)
|
||||||
p.error('cannot used type `$typ.name` as type `$arg.typ.name` in argument to `$fn_name`')
|
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 p.tok.kind == .comma {
|
||||||
if i < f.args.len - 1 {
|
p.error('too many arguments in call to `$fn_name`')
|
||||||
p.check(.comma)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if p.tok.kind == .comma {
|
// else{
|
||||||
p.error('too many arguments in call to `$fn_name`')
|
// p.error('unknown function `$fn_name`')
|
||||||
}
|
// }
|
||||||
|
// exit(0)
|
||||||
p.check(.rpar)
|
p.check(.rpar)
|
||||||
node := ast.CallExpr{
|
node := ast.CallExpr{
|
||||||
name: fn_name
|
name: fn_name
|
||||||
|
|
Loading…
Reference in New Issue