diff --git a/src/V3Param.cpp b/src/V3Param.cpp index 282f6e9f2..7df3961c9 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -1150,7 +1150,12 @@ class ParamVisitor final : public VNVisitor { if (nodep->ifacep()) visitCellOrClassRef(nodep, true); } void visit(AstClassRefDType* nodep) override { visitCellOrClassRef(nodep, false); } - void visit(AstClassOrPackageRef* nodep) override { visitCellOrClassRef(nodep, false); } + void visit(AstClassOrPackageRef* nodep) override { + // If it points to a typedef it is not really a class reference. That typedef will be + // visited anyway (from its parent node), so even if it points to a parameterized class + // type, the instance will be created. + if (!VN_IS(nodep->classOrPackageNodep(), Typedef)) visitCellOrClassRef(nodep, false); + } // Make sure all parameters are constantified void visit(AstVar* nodep) override { diff --git a/test_regress/t/t_class_param_typedef2.pl b/test_regress/t/t_class_param_typedef2.pl new file mode 100755 index 000000000..1aa73f80a --- /dev/null +++ b/test_regress/t/t_class_param_typedef2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2022 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(simulator => 1); + +compile( + ); + +execute( + check_finished => 1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_class_param_typedef2.v b/test_regress/t/t_class_param_typedef2.v new file mode 100644 index 000000000..ea2e74a1a --- /dev/null +++ b/test_regress/t/t_class_param_typedef2.v @@ -0,0 +1,34 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2023 by Antmicro Ltd. +// SPDX-License-Identifier: CC0-1.0 + +virtual class Virt; +endclass + +class MyInt; + int x; +endclass + +class uvm_object_registry #( + type T = Virt +); + static function T create_object(); + T obj = new(); + obj.x = 1; + return obj; + endfunction +endclass + +typedef uvm_object_registry#(MyInt) type_id; + +module t; + initial begin + MyInt mi = type_id::create_object(); + if (mi.x != 1) $stop; + + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule