From 14066871e5d0776400ce508bd5a8acba6a1e0007 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 6 Aug 2026 22:24:41 -0700 Subject: [PATCH] Allow const property initialization in nested constructor blocks A named block inside a class constructor has its own scope. The const property assignment check currently tests the name of this immediate scope and rejects the assignment because it is not named `new` or `new@`. Find the containing class method before deciding whether the assignment is in the constructor. Assignments from nested blocks in other methods remain invalid. Signed-off-by: Lars-Peter Clausen --- elab_lval.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/elab_lval.cc b/elab_lval.cc index 15c81d9ed..51e674be9 100644 --- a/elab_lval.cc +++ b/elab_lval.cc @@ -1137,13 +1137,16 @@ NetAssign_* PEIdent::elaborate_lval_net_class_member_(Design*des, NetScope*scope return lv; } else if (qual.test_const()) { + auto method_scope = find_method_containing_scope(*this, scope); if (class_type->get_prop_initialized(pidx)) { cerr << get_fileline() << ": error: " << "Property " << class_type->get_prop_name(pidx) << " is constant in this method." << " (scope=" << scope_path(scope) << ")" << endl; des->errors++; - } else if (scope->basename() != "new" && scope->basename() != "new@") { + } else if (!method_scope || + (method_scope->basename() != "new" && + method_scope->basename() != "new@")) { cerr << get_fileline() << ": error: " << "Property " << class_type->get_prop_name(pidx) << " is constant in this method."