From 55d78cf1a8aef439c0f136b7889ad63423237b08 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 21 Jun 2026 14:22:47 -0700 Subject: [PATCH] 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 --- elab_expr.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/elab_expr.cc b/elab_expr.cc index 6c9d7b17a..1035ebe8a 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -3474,10 +3474,12 @@ NetExpr* PECallFunction::elaborate_expr_method_(Design*des, NetScope*scope, } if (method_name == "substr") { - if (parms_.size() != 2) + if (parms_.size() != 2) { cerr << get_fileline() << ": error: Method `substr()`" << " requires 2 arguments, got " << parms_.size() << "." << endl; + des->errors += 1; + } static const std::vector parm_names = { perm_string::literal("i"), @@ -3493,8 +3495,12 @@ NetExpr* PECallFunction::elaborate_expr_method_(Design*des, NetScope*scope, sys_expr->parm(0, sub_expr); 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; + } auto expr = elaborate_rval_expr(des, scope, &netvector_t::atom2u32,