Reject invalid casts to real

Only vector types can be cast to real. Report an error when trying to cast
a different type instead of triggering an assert later on.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2025-01-12 19:38:19 -08:00
parent 30123f8945
commit 4c03ac5b36
1 changed files with 14 additions and 1 deletions

View File

@ -3706,7 +3706,20 @@ NetExpr* PECastType::elaborate_expr(Design*des, NetScope*scope,
NetExpr*tmp = 0;
if (dynamic_cast<const netreal_t*>(target_type_)) {
return cast_to_real(sub);
switch (sub->expr_type()) {
case IVL_VT_REAL:
return sub;
case IVL_VT_LOGIC:
case IVL_VT_BOOL:
return cast_to_real(sub);
default:
break;
}
cerr << get_fileline() << " error: Expression of type `"
<< sub->expr_type() << "` can not be cast to target type `real`."
<< endl;
des->errors++;
return nullptr;
} else if (dynamic_cast<const netstring_t*>(target_type_)) {
if (base_->expr_type() == IVL_VT_STRING)
return sub; // no conversion