diff --git a/elab_expr.cc b/elab_expr.cc index b8ea451b3..b1364b281 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -1932,15 +1932,18 @@ bool PEIdent::calculate_up_do_width_(Design*des, NetScope*scope, need_constant_expr = false; NetEConst*wid_c = dynamic_cast(wid_ex); - if (wid_c == 0) { - cerr << get_fileline() << ": error: Indexed part width must be " - << "constant. Expression in question is..." << endl; - cerr << get_fileline() << ": : " << *wid_ex << endl; + wid = wid_c? wid_c->value().as_ulong() : 0; + if (wid == 0) { + cerr << index_tail.lsb->get_fileline() << ": error: " + "Indexed part widths must be constant and greater than zero." + << endl; + cerr << index_tail.lsb->get_fileline() << ": : " + "This part width expression violates the rule: " + << *index_tail.lsb << endl; des->errors += 1; flag = false; + wid = 1; } - - wid = wid_c? wid_c->value().as_ulong() : 1; delete wid_ex; return flag; diff --git a/expr_synth.cc b/expr_synth.cc index 36908c9ad..8d5a3a9ee 100644 --- a/expr_synth.cc +++ b/expr_synth.cc @@ -1048,6 +1048,7 @@ NetNet* NetESelect::synthesize(Design *des, NetScope*scope, NetExpr*root) NetPartSelect::VP); des->add_node(sel); + ivl_assert(*this, select_width > 0); NetNet*tmp = new NetNet(scope, scope->local_symbol(), NetNet::WIRE, select_width); tmp->data_type(sub->data_type());