Skip to content

Commit

Permalink
Parser: boolcast lhs of logical or expression even if not evaluatin…
Browse files Browse the repository at this point in the history
…g it

Ensure that the value, if present, is zero or one.

Closes #668
  • Loading branch information
ehaas authored and Vexu committed Apr 6, 2024
1 parent 9f31df3 commit e9e4dc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6415,6 +6415,8 @@ fn lorExpr(p: *Parser) Error!Result {
if (try lhs.adjustTypes(tok, &rhs, p, .boolean_logic)) {
const res = lhs.val.toBool(p.comp) or rhs.val.toBool(p.comp);
lhs.val = Value.fromBool(res);
} else {
lhs.val.boolCast(p.comp);
}
try lhs.boolRes(p, .bool_or_expr, rhs);
}
Expand Down
4 changes: 4 additions & 0 deletions test/cases/float values.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
_Static_assert(-1.0 - 1.0 == -2.0, "");
_Static_assert(-2.0f == -2.0, "");
_Static_assert(1.0 == (2.0||0), "");
void foo(void) {
float f = 2.0 || 0;
}

0 comments on commit e9e4dc9

Please sign in to comment.