diff --git a/elab_expr.cc b/elab_expr.cc index 671381e62..306f2e319 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -1983,6 +1983,15 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope, } } else { + // Check if the expression could be resolved. If test_width + // failed to find the identifier, expr_type will be NO_TYPE. + if (expr->expr_type() == IVL_VT_NO_TYPE) { + // Try to elaborate the expression to get a proper error + // message about the undefined identifier. + NetExpr *tmp = expr->elaborate_expr(des, scope, (unsigned)1, flags); + if (tmp) delete tmp; + return 0; + } use_width = expr->expr_width(); if (debug_elaborate) { cerr << get_fileline() << ": PECallFunction::elaborate_sfunc_: " diff --git a/ivtest/gold/br_gh1112.gold b/ivtest/gold/br_gh1112.gold new file mode 100644 index 000000000..39090a992 --- /dev/null +++ b/ivtest/gold/br_gh1112.gold @@ -0,0 +1,2 @@ +./ivltests/br_gh1112.v:4: error: Unable to bind parameter `value' in `top' +1 error(s) during elaboration. diff --git a/ivtest/ivltests/br_gh1112.v b/ivtest/ivltests/br_gh1112.v new file mode 100644 index 000000000..508440ea5 --- /dev/null +++ b/ivtest/ivltests/br_gh1112.v @@ -0,0 +1,6 @@ +// Test for GitHub issue #1112 +// $bits() with non-existent identifier should produce an error +module top; + localparam width = $bits(value); // 'value' doesn't exist - should error + initial $display(width); +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index dade32337..8f4ea3733 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -989,3 +989,4 @@ partsel_real_idx CE,-g2012 ivltests gold=partsel_real_idx.gold ipsdownsel_real_idx CE,-g2012 ivltests gold=ipsdownsel_real_idx.gold ipsupsel_real_idx CE,-g2012 ivltests gold=ipsupsel_real_idx.gold real_edges CE,-g2012 ivltests gold=real_edges.gold +br_gh1112 CE,-g2009 ivltests gold=br_gh1112.gold