From 9ee5fd05857002db8d3f14007ab2bf4dfb2640c0 Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Tue, 20 Jun 2023 20:10:07 +0200 Subject: [PATCH] Fix handling of ref types in initial values of type parameters (#4304) --- src/V3AstNodeDType.h | 1 + src/V3Param.cpp | 2 +- test_regress/t/t_class_param_typedef.v | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/V3AstNodeDType.h b/src/V3AstNodeDType.h index 7645fb3e6..bb6599ca9 100644 --- a/src/V3AstNodeDType.h +++ b/src/V3AstNodeDType.h @@ -1077,6 +1077,7 @@ public: AstRefDType(FileLine* fl, FlagTypeOfExpr, AstNode* typeofp) : ASTGEN_SUPER_RefDType(fl) { this->typeofp(typeofp); + if (AstNodeDType* const dtp = VN_CAST(typeofp, NodeDType)) refDTypep(dtp); } ASTGEN_MEMBERS_AstRefDType; // METHODS diff --git a/src/V3Param.cpp b/src/V3Param.cpp index ba39ef6e6..2e67fbe90 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -709,7 +709,7 @@ class ParamProcessor final : public VNDeleter { } } else if (AstParamTypeDType* const modvarp = pinp->modPTypep()) { AstNodeDType* const exprp = VN_CAST(pinp->exprp(), NodeDType); - const AstNodeDType* const origp = modvarp->subDTypep(); + const AstNodeDType* const origp = modvarp->skipRefToEnump(); if (!exprp) { pinp->v3error("Parameter type pin value isn't a type: Param " << pinp->prettyNameQ() << " of " << nodep->prettyNameQ()); diff --git a/test_regress/t/t_class_param_typedef.v b/test_regress/t/t_class_param_typedef.v index 0218b205a..d9f9f73ce 100644 --- a/test_regress/t/t_class_param_typedef.v +++ b/test_regress/t/t_class_param_typedef.v @@ -33,14 +33,39 @@ class Cls2; typedef Bar#(Cls2) type_id; endclass +typedef int my_int; + +class ClsTypedefParam #(type T=my_int); + int x; +endclass + +class uvm_sequencer #(type REQ=int, RSP=REQ); + int x; + typedef uvm_sequencer #(REQ, RSP) this_type; +endclass + module t; initial begin Cls1::type_id bar1 = new; Cls2::type_id bar2 = new; + ClsTypedefParam #(int) cls_int = new; + ClsTypedefParam#() cls_def; + + uvm_sequencer #(int, int) uvm_seq1 = new; + uvm_sequencer #(int, int)::this_type uvm_seq2; + if (bar1.get_x() != 1) $stop; if (bar2.get_x() != 2) $stop; + cls_int.x = 1; + cls_def = cls_int; + if (cls_def.x != 1) $stop; + + uvm_seq1.x = 2; + uvm_seq2 = uvm_seq1; + if (uvm_seq2.x != 2) $stop; + $write("*-* All Finished *-*\n"); $finish; end