From 4e8a8a039881155724b220e000330923fe032e27 Mon Sep 17 00:00:00 2001 From: Igor Zaworski <84542280+igorosky@users.noreply.github.com> Date: Fri, 11 Jul 2025 03:11:09 +0200 Subject: [PATCH] Fix param-dependent class typedef linking (#6171) --- src/V3LinkDot.cpp | 6 ++++++ test_regress/t/t_typedef_param_class.py | 18 ++++++++++++++++++ test_regress/t/t_typedef_param_class.v | 23 +++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100755 test_regress/t/t_typedef_param_class.py create mode 100644 test_regress/t/t_typedef_param_class.v diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index d67934d68..1b39283f8 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -4471,6 +4471,12 @@ class LinkDotResolveVisitor final : public VNVisitor { nodep->classOrPackagep(cpackagerefp->classOrPackageSkipp()); if (!VN_IS(nodep->classOrPackagep(), Class) && !VN_IS(nodep->classOrPackagep(), Package)) { + if (m_statep->forPrimary()) { + // It may be a type that comes from parameter class that is not + // instantioned yet + iterate(cpackagep); + return; + } // Likely impossible, as error thrown earlier cpackagerefp->v3error( // LCOV_EXCL_LINE "'::' expected to reference a class/package but referenced '" diff --git a/test_regress/t/t_typedef_param_class.py b/test_regress/t/t_typedef_param_class.py new file mode 100755 index 000000000..f989a35fb --- /dev/null +++ b/test_regress/t/t_typedef_param_class.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2025 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 + +import vltest_bootstrap + +test.scenarios('simulator') + +test.compile() + +test.execute() + +test.passes() diff --git a/test_regress/t/t_typedef_param_class.v b/test_regress/t/t_typedef_param_class.v new file mode 100644 index 000000000..7d6fc6ac6 --- /dev/null +++ b/test_regress/t/t_typedef_param_class.v @@ -0,0 +1,23 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2025 by Antmicro. +// SPDX-License-Identifier: CC0-1.0 + +class Class1 #(type T); + typedef T::Some_type2 Some_type1; +endclass + +class Class2; + typedef int Some_type2; +endclass + +module t; + initial begin + int value0 = 7; + Class1#(Class2)::Some_type1 value1 = value0; + int value2 = value1; + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule