Fix referencing module variables above classes (#6304)

Signed-off-by: Artur Bieniek <[email protected]>
This commit is contained in:
Artur Bieniek
2025-08-18 08:51:25 -04:00
committed by GitHub
parent 9dc31e4556
commit 53c59e7ac7
3 changed files with 64 additions and 3 deletions
+12 -3
View File
@@ -68,9 +68,18 @@ class ScopeVisitor final : public VNVisitor {
UASSERT_OBJ(it2 != m_packageScopes.end(), nodep, "Can't locate package scope");
scopep = it2->second;
}
const auto it3 = m_varScopes.find(std::make_pair(nodep->varp(), scopep));
UASSERT_OBJ(it3 != m_varScopes.end(), nodep, "Can't locate varref scope");
AstVarScope* const varscp = it3->second;
// Search up the scope hierarchy for the variable
AstVarScope* varscp = nullptr;
AstScope* searchScopep = scopep;
while (searchScopep) {
const auto it3 = m_varScopes.find(std::make_pair(nodep->varp(), searchScopep));
if (it3 != m_varScopes.end()) {
varscp = it3->second;
break;
}
searchScopep = searchScopep->aboveScopep();
}
UASSERT_OBJ(varscp, nodep, "Can't locate varref scope");
nodep->varScopep(varscp);
}
}