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:
parent
30123f8945
commit
4c03ac5b36
15
elab_expr.cc
15
elab_expr.cc
|
|
@ -3706,7 +3706,20 @@ NetExpr* PECastType::elaborate_expr(Design*des, NetScope*scope,
|
||||||
|
|
||||||
NetExpr*tmp = 0;
|
NetExpr*tmp = 0;
|
||||||
if (dynamic_cast<const netreal_t*>(target_type_)) {
|
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_)) {
|
} else if (dynamic_cast<const netstring_t*>(target_type_)) {
|
||||||
if (base_->expr_type() == IVL_VT_STRING)
|
if (base_->expr_type() == IVL_VT_STRING)
|
||||||
return sub; // no conversion
|
return sub; // no conversion
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue