Skip to content

Commit

Permalink
parse if (true): x
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 13, 2024
1 parent 356908f commit 908c2cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions compiler/parser/expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions tests/valid/if_expr.ri
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
fn main() {
if (true) {
y;
let b = if (true) {
y
} else {
x;
}
x
};

let add = 0;
if (1 + 2 == 3) {
add = 1;
} else {
add = 4;
}

if (true): x;
}

0 comments on commit 908c2cc

Please sign in to comment.