Fix non-member identifiers used inside constraints (#7033)

This commit is contained in:
Pawel Kojma
2026-02-11 05:18:24 -08:00
committed by GitHub
parent 22dc437dbb
commit 5d12ae3a2f
3 changed files with 60 additions and 8 deletions
+8 -8
View File
@@ -291,8 +291,6 @@ class RandomizeMarkVisitor final : public VNVisitor {
targetClassp->foreachMember([&](AstClass* const, AstConstraint* const existingConstrp) {
if (existingConstrp->name() == newName) {
// Multiple paths lead to same constraint - unsupported pattern
std::string fullPath = rootVarRefp->name();
for (AstVar* pathVar : newPath) { fullPath += "." + pathVar->name(); }
isDuplicate = true;
}
});
@@ -301,12 +299,14 @@ class RandomizeMarkVisitor final : public VNVisitor {
AstConstraint* const cloneConstrp = constrp->cloneTree(false);
cloneConstrp->name(newName);
cloneConstrp->foreach([&](AstVarRef* varRefp) {
AstNodeExpr* const chainp = buildMemberSelChain(rootVarRefp, newPath);
AstMemberSel* const finalSelp
= new AstMemberSel{varRefp->fileline(), chainp, varRefp->varp()};
finalSelp->user2p(m_classp);
varRefp->replaceWith(finalSelp);
VL_DO_DANGLING(varRefp->deleteTree(), varRefp);
if (varRefp->varp()->isClassMember()) {
AstNodeExpr* const chainp = buildMemberSelChain(rootVarRefp, newPath);
AstMemberSel* const finalSelp
= new AstMemberSel{varRefp->fileline(), chainp, varRefp->varp()};
finalSelp->user2p(m_classp);
varRefp->replaceWith(finalSelp);
VL_DO_DANGLING(varRefp->deleteTree(), varRefp);
}
});
// Add constraint directly to the target class