Handle missing string substr() arguments

The string substr() method reports an error if it is called with the wrong
number of arguments, but the error was not counted and elaboration continued
with missing function arguments. A call such as `s.substr(0)` could therefore
crash after printing the diagnostic.

Count the arity error and fill missing internal arguments with dummy constants
so elaboration can recover without building an incomplete system function call.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-06-21 14:22:47 -07:00
parent 78750c51d0
commit 55d78cf1a8
1 changed files with 8 additions and 2 deletions

View File

@ -3474,10 +3474,12 @@ NetExpr* PECallFunction::elaborate_expr_method_(Design*des, NetScope*scope,
} }
if (method_name == "substr") { if (method_name == "substr") {
if (parms_.size() != 2) if (parms_.size() != 2) {
cerr << get_fileline() << ": error: Method `substr()`" cerr << get_fileline() << ": error: Method `substr()`"
<< " requires 2 arguments, got " << parms_.size() << " requires 2 arguments, got " << parms_.size()
<< "." << endl; << "." << endl;
des->errors += 1;
}
static const std::vector<perm_string> parm_names = { static const std::vector<perm_string> parm_names = {
perm_string::literal("i"), perm_string::literal("i"),
@ -3493,8 +3495,12 @@ NetExpr* PECallFunction::elaborate_expr_method_(Design*des, NetScope*scope,
sys_expr->parm(0, sub_expr); sys_expr->parm(0, sub_expr);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
if (!args[i]) if (!args[i]) {
NetEConst*expr = make_const_0(32);
expr->set_line(*this);
sys_expr->parm(i + 1, expr);
continue; continue;
}
auto expr = elaborate_rval_expr(des, scope, auto expr = elaborate_rval_expr(des, scope,
&netvector_t::atom2u32, &netvector_t::atom2u32,