Skip to content

Commit

Permalink
Error casting bool const to other than bit<1>
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDodd committed Feb 18, 2024
1 parent a34e426 commit 144972b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,9 @@ const IR::Node *DoConstantFolding::postorder(IR::Cast *e) {
if (auto arg = expr->to<IR::Constant>()) {
return cast(arg, arg->base, type);
} else if (auto arg = expr->to<IR::BoolLiteral>()) {
if (type->isSigned || type->size != 1)
error(ErrorType::ERR_INVALID, "%1%: Cannot cast %1% driectly to %2% (use bit<1>)",
arg, type);
int v = arg->value ? 1 : 0;
return new IR::Constant(e->srcInfo, type, v, 10);
} else if (expr->is<IR::Member>()) {
Expand Down

0 comments on commit 144972b

Please sign in to comment.