From 8e82440a55a63b65397d443fc00c6659efd4b586 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 13 Nov 2024 19:15:10 -0500 Subject: [PATCH] Fix extranous local:: error --- src/V3LinkDot.cpp | 56 ++++++++++++++------------ test_regress/t/t_package_local_bad.out | 3 -- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 5923fce82..1c6aaf93e 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -2147,7 +2147,7 @@ class LinkDotResolveVisitor final : public VNVisitor { enum DotPosition : uint8_t { // Must match ascii() method below DP_NONE = 0, // Not under a DOT - DP_PACKAGE, // {package}:: DOT + DP_PACKAGE, // {package-or-class}:: DOT DP_FIRST, // {scope-or-var} DOT DP_SCOPE, // DOT... {scope-or-var} DOT DP_FINAL, // [DOT...] {var-or-func-or-dtype} with no following dots @@ -2814,7 +2814,7 @@ class LinkDotResolveVisitor final : public VNVisitor { bool allowFTask = false; bool staticAccess = false; if (m_ds.m_dotPos == DP_PACKAGE) { - // {package}::{a} + // {package-or-class}::{a} AstNodeModule* classOrPackagep = nullptr; expectWhat = "scope/variable/func"; allowScope = true; @@ -3179,20 +3179,37 @@ class LinkDotResolveVisitor final : public VNVisitor { nodep, "ClassRef has unlinked class"); UASSERT_OBJ(m_statep->forPrimary() || !nodep->paramsp(), nodep, "class reference parameter not removed by V3Param"); - VL_RESTORER(m_ds); - VL_RESTORER(m_pinSymp); - // ClassRef's have pins, so track - if (nodep->classOrPackagep()) { - m_pinSymp = m_statep->getNodeSym(nodep->classOrPackagep()); + { + // ClassRef's have pins, so track + VL_RESTORER(m_ds); + VL_RESTORER(m_pinSymp); + + if (nodep->classOrPackagep()) { + m_pinSymp = m_statep->getNodeSym(nodep->classOrPackagep()); + } + AstClass* const refClassp = VN_CAST(nodep->classOrPackagep(), Class); + // Make sure any extends() are properly imported within referenced class + if (refClassp && !m_statep->forPrimary()) classExtendImport(refClassp); + + m_ds.init(m_curSymp); + UINFO(4, indent() << "(Backto) Link ClassOrPackageRef: " << nodep << endl); + iterateChildren(nodep); + + AstClass* const modClassp = VN_CAST(m_modp, Class); + if (m_statep->forPrimary() && refClassp && !nodep->paramsp() + && nodep->classOrPackagep()->hasGParam() + // Don't warn on typedefs, which are hard to know if there's a param somewhere + // buried + && VN_IS(nodep->classOrPackageNodep(), Class) + // References to class:: within class itself are OK per IEEE (UVM does this) + && modClassp != refClassp) { + nodep->v3error( + "Reference to parameterized class without #() (IEEE 1800-2023 8.25.1)\n" + << nodep->warnMore() << "... Suggest use '" + << nodep->classOrPackageNodep()->prettyName() << "#()'"); + } } - AstClass* const refClassp = VN_CAST(nodep->classOrPackagep(), Class); - // Make sure any extends() are properly imported within referenced class - if (refClassp && !m_statep->forPrimary()) classExtendImport(refClassp); - - m_ds.init(m_curSymp); - UINFO(4, indent() << "(Backto) Link ClassOrPackageRef: " << nodep << endl); - iterateChildren(nodep); if (nodep->name() == "local::") { if (!m_randSymp) { @@ -3202,17 +3219,6 @@ class LinkDotResolveVisitor final : public VNVisitor { return; } } - AstClass* const modClassp = VN_CAST(m_modp, Class); - if (m_statep->forPrimary() && refClassp && !nodep->paramsp() - && nodep->classOrPackagep()->hasGParam() - // Don't warn on typedefs, which are hard to know if there's a param somewhere buried - && VN_IS(nodep->classOrPackageNodep(), Class) - // References to class:: within class itself are OK per IEEE (UVM does this) - && modClassp != refClassp) { - nodep->v3error("Reference to parameterized class without #() (IEEE 1800-2023 8.25.1)\n" - << nodep->warnMore() << "... Suggest use '" - << nodep->classOrPackageNodep()->prettyName() << "#()'"); - } } void visit(AstConstraintRef* nodep) override { if (nodep->user3SetOnce()) return; diff --git a/test_regress/t/t_package_local_bad.out b/test_regress/t/t_package_local_bad.out index e219c46a2..8a3dbab30 100644 --- a/test_regress/t/t_package_local_bad.out +++ b/test_regress/t/t_package_local_bad.out @@ -1,7 +1,4 @@ %Error: t/t_package_local_bad.v:9:16: Illegal 'local::' outside 'randomize() with' (IEEE 1800-2023 18.7.1) 9 | $display(local::x); | ^~~~~ -%Error: t/t_package_local_bad.v:9:23: Can't find definition of scope/variable/func: 'x' - 9 | $display(local::x); - | ^ %Error: Exiting due to