checker: handle json.decode correctly
parent
f49ef39708
commit
0f251e9ede
|
@ -935,8 +935,8 @@ pub fn (mut c Checker) check_expr_opt_call(x ast.Expr, xtype table.Type, is_retu
|
|||
ast.CallExpr {
|
||||
if it.return_type.flag_is(.optional) {
|
||||
c.check_or_block(it, xtype, is_return_used)
|
||||
} else if it.or_block.is_used {
|
||||
c.error('unexpected `or` block, the function does not return an optional',
|
||||
} else if it.or_block.is_used && it.name != 'json.decode' { // TODO remove decode hack
|
||||
c.error('unexpected `or` block, the function `$it.name` does not return an optional',
|
||||
it.pos)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,11 @@ pub fn (mut p Parser) call_expr(is_c, is_js bool, mod string) ast.CallExpr {
|
|||
} else {
|
||||
name
|
||||
}
|
||||
mut is_or_block_used := false
|
||||
if fn_name == 'json.decode' {
|
||||
// Makes name_expr() parse the type (`User` in `json.decode(User, txt)`)`
|
||||
p.expecting_type = true
|
||||
p.expecting_type = true // Makes name_expr() parse the type (`User` in `json.decode(User, txt)`)`
|
||||
p.expr_mod = ''
|
||||
is_or_block_used = true
|
||||
}
|
||||
p.check(.lpar)
|
||||
args := p.call_args()
|
||||
|
@ -35,7 +36,6 @@ pub fn (mut p Parser) call_expr(is_c, is_js bool, mod string) ast.CallExpr {
|
|||
len: last_pos.pos - first_pos.pos + last_pos.len
|
||||
}
|
||||
mut or_stmts := []ast.Stmt{}
|
||||
mut is_or_block_used := false
|
||||
if p.tok.kind == .key_orelse {
|
||||
p.inside_or_expr = true
|
||||
p.next()
|
||||
|
|
Loading…
Reference in New Issue