From e897e3ab5fe14ba1b4de3aa71d157846de833bdb Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 19 Sep 2022 13:05:34 +0200 Subject: [PATCH] Avoid confusing type compatibility error messages Icarus allows to pass a value of the element type as an argument to the dynamic new operator. To allow this the type compatibility check for dynamic arrays allows both the dynamic array type itself and also the element type. This currently leads to a confusing error message if neither type matches. The error message will say that the passed value is not compatible with the element type. E.g. ``` real d1[]; int d2[]; d1 = d2; ``` results in ``` error: the type of the variable 'd2' doesn't match the context type. : variable type=dynamic array of netvector_t:bool signed[31:0] : context type=real ``` This is slightly confusing. Change the way the error message is reported so that the context type is the type of the dynamic array and not the element. With the change the above results in ``` error: the type of the variable 'd2' doesn't match the context type. : variable type=dynamic array of netvector_t:bool signed[31:0] : context type=dynamic array of real ``` Signed-off-by: Lars-Peter Clausen --- elab_expr.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/elab_expr.cc b/elab_expr.cc index c643f1466..9772b3f07 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -4377,6 +4377,7 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope, << "Found net " << net->name() << " for expr " << *this << endl; } + ivl_type_t check_type = ntype; if (const netdarray_t*array_type = dynamic_cast (ntype)) { if (array_type->type_compatible(net->net_type())) { NetESignal*tmp = new NetESignal(net); @@ -4386,10 +4387,10 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope, // Icarus allows a dynamic array to be initialised with a // single elementary value, so try that next. - ntype = array_type->element_type(); + check_type = array_type->element_type(); } - if (! ntype->type_compatible(net->net_type())) { + if (! check_type->type_compatible(net->net_type())) { cerr << get_fileline() << ": error: the type of the variable '" << path_ << "' doesn't match the context type." << endl;