diff --git a/compiler/parser/expr.v b/compiler/parser/expr.v index a8f62db3..96b1ad82 100644 --- a/compiler/parser/expr.v +++ b/compiler/parser/expr.v @@ -348,6 +348,9 @@ fn (mut p Parser) parse_if_expr() ast.Expr { p.expect(.lparen) cond := p.parse_expr() p.expect(.rparen) + if p.tok.kind != .lbrace { + p.expect(.colon) + } branches << ast.IfBranch{cond, p.parse_expr(), pos} if p.tok.kind != .kw_else { break diff --git a/tests/valid/if_expr.ri b/tests/valid/if_expr.ri index c9d2655d..78c6f241 100644 --- a/tests/valid/if_expr.ri +++ b/tests/valid/if_expr.ri @@ -1,9 +1,9 @@ fn main() { - if (true) { - y; + let b = if (true) { + y } else { - x; - } + x + }; let add = 0; if (1 + 2 == 3) { @@ -11,4 +11,6 @@ fn main() { } else { add = 4; } + + if (true): x; }