diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 177227934..e6e248ded 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -918,15 +918,22 @@ class LinkDotFindVisitor final : public VNVisitor { nodep->isExternDef(true); // So we check there's a matching extern nodep->classOrPackagep()->unlinkFrBack()->deleteTree(); // Any "Type::" reference in the function's IO are really "MovedToClass::" references - if (nodep->fvarp()) - nodep->fvarp()->foreach([this, classp](AstClassOrPackageRef* refp) { // - if (refp->name() == classp->name() && !refp->paramsp()) { - UINFO(9, "Cleaning up external function type for class " << refp); - pushDeletep(refp->unlinkFrBack()); - } - }); + if (nodep->fvarp()) moveExternFuncDeclRefs(nodep->fvarp(), classp); + for (AstNode* stmtp = nodep->stmtsp(); stmtp; stmtp = stmtp->nextp()) { + if (AstVar* const portp = VN_CAST(stmtp, Var)) { + if (portp->isIO()) moveExternFuncDeclRefs(portp, classp); + } + } } } + void moveExternFuncDeclRefs(AstNode* nodep, AstClass* classp) { + nodep->foreach([this, classp](AstClassOrPackageRef* refp) { // + if (refp->name() == classp->name() && !refp->paramsp()) { + UINFO(9, "Cleaning up external function type for class " << refp); + pushDeletep(refp->unlinkFrBack()); + } + }); + } // VISITORS void visit(AstNetlist* nodep) override { // FindVisitor:: diff --git a/test_regress/t/t_class_extern_typeref.v b/test_regress/t/t_class_extern_typeref.v index 3501ecb91..3eb715e5c 100644 --- a/test_regress/t/t_class_extern_typeref.v +++ b/test_regress/t/t_class_extern_typeref.v @@ -7,6 +7,7 @@ class uvm_process_guard#(type T=int); T m_context; extern function T get_context(); + extern function new(T ctxt); endclass // When this moves into class, note it's not uvm_process_guard#()::T @@ -15,6 +16,10 @@ function uvm_process_guard::T uvm_process_guard::get_context(); return this.m_context; endfunction +function uvm_process_guard::new(uvm_process_guard::T ctxt); + this.m_context = ctxt; +endfunction : new + class uvm_sequence_base; typedef uvm_process_guard#(uvm_sequence_base) m_guard_t; endclass