diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 7a32e1aca5..feed2eb30a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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) } } diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 4969f03ffd..e1243ba678 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -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()