-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error casting bool const to other than bit<1> #4419
Conversation
I am quite surprised this is not checked in type checking though. That would seem like a better place to do it (especially if we want to boot out the constant folding out of frontend in future!). The type checker checks it for variable access, why not for constant? |
04015f4
to
144972b
Compare
The basic issue is that we do constant folding before type checking so we can deal with |
144972b
to
e2df905
Compare
frontends/common/constantFolding.cpp
Outdated
@@ -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>)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error(ErrorType::ERR_INVALID, "%1%: Cannot cast %1% driectly to %2% (use bit<1>)", | |
error(ErrorType::ERR_INVALID, "%1%: Cannot cast %1% directly to %2% (use bit<1>)", |
e2df905
to
6f3c393
Compare
Trivial corner case that should not be allowed according to the spec