Skip to content

Commit

Permalink
if_expr: parse expr instead of stmts
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 13, 2024
1 parent 4fc13a2 commit 356908f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions compiler/ast/Expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ pub:

pub struct IfBranch {
pub:
cond ?Expr
stmts []Stmt
pos FilePos
cond ?Expr
expr Expr
pos FilePos
}

@[inline]
Expand Down
4 changes: 2 additions & 2 deletions compiler/parser/expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ fn (mut p Parser) parse_if_expr() ast.Expr {
pos := p.tok.pos
for {
if p.accept(.kw_else) && p.tok.kind != .kw_if {
branches << ast.IfBranch{none, p.parse_stmts(), pos}
branches << ast.IfBranch{none, p.parse_expr(), pos}
break
}
p.expect(.kw_if)
p.expect(.lparen)
cond := p.parse_expr()
p.expect(.rparen)
branches << ast.IfBranch{cond, p.parse_stmts(), pos}
branches << ast.IfBranch{cond, p.parse_expr(), pos}
if p.tok.kind != .kw_else {
break
}
Expand Down

0 comments on commit 356908f

Please sign in to comment.