Skip to content

Commit

Permalink
parser: fix infix expr handling with cast on left side of << operator (
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Nov 24, 2023
1 parent 67fabdd commit 90d3523
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/parser/expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ fn (mut p Parser) expr_with_left(left ast.Expr, precedence int, is_stmt_ident bo
} else {
return node
}
} else if p.tok.kind == .left_shift && p.is_stmt_ident {
} else if node !is ast.CastExpr && p.tok.kind == .left_shift && p.is_stmt_ident {
// arr << elem
tok := p.tok
mut pos := tok.pos()
Expand Down
12 changes: 12 additions & 0 deletions vlib/v/tests/cast_precedence_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn test_main() {
assert (u8(1) << 1 | 1) == 3
assert (match 0 {
0 { u8(1) << 1 | 1 }
else { 0 }
}) == 3
assert (if true {
u8(1) << 1 | 1
} else {
0
}) == 3
}

0 comments on commit 90d3523

Please sign in to comment.