diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index f1759de79..bb842f9dd 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -1011,6 +1011,12 @@ class LinkDotFindVisitor final : public VNVisitor { if (!m_explicitNew && m_statep->forPrimary()) makeImplicitNew(nodep); } } + void visit(AstClassOrPackageRef* nodep) override { + if (!nodep->classOrPackageNodep() && nodep->name() == "$unit") { + nodep->classOrPackageNodep(v3Global.rootp()->dollarUnitPkgAddp()); + } + iterateChildren(nodep); + } void visit(AstScope* nodep) override { UASSERT_OBJ(m_statep->forScopeCreation(), nodep, "Scopes should only exist right after V3Scope"); @@ -3806,6 +3812,7 @@ class LinkDotResolveVisitor final : public VNVisitor { if (AstClassOrPackageRef* lookNodep = VN_CAST(dotp->lhsp(), ClassOrPackageRef)) { iterate(lookNodep); cprp = dotp->rhsp(); + UASSERT_OBJ(lookNodep->classOrPackagep(), nodep, "Bad package link"); lookSymp = m_statep->getNodeSym(lookNodep->classOrPackagep()); } else { dotp->lhsp()->v3error("Attempting to extend" // LCOV_EXCL_LINE diff --git a/src/verilog.y b/src/verilog.y index 8e2373723..d795dd611 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -7307,7 +7307,7 @@ dollarUnitNextId: // $unit // // if not needed must use packageClassScopeNoId // // Must call nextId without any additional tokens following yD_UNIT - { $$ = new AstClassOrPackageRef{$1, "$unit", PARSEP->unitPackage($1), nullptr}; + { $$ = new AstClassOrPackageRef{$1, "$unit", nullptr, nullptr}; SYMP->nextId(PARSEP->rootp()); } ;