From 2ab34b5eeb2ccae756c7d47fde72eb1b7b5529fa Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 9 Apr 2023 19:46:47 -0400 Subject: [PATCH] Fix false error on new const assignment (#4098). --- Changes | 1 + src/V3Width.cpp | 4 ++-- test_regress/t/t_class_new.v | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 52905d12a..715c7827b 100644 --- a/Changes +++ b/Changes @@ -39,6 +39,7 @@ Verilator 5.009 devel * Fix false LATCH warning on --assert 'unique else if' (#4033) ($4054). [Jesse Taube] * Fix characters from DEFENV literals for conda (#4035) (#4044). [Tim Snyder] * Fix interface generate begin (#4065). [Srinivasan Venkataramanan] +* Fix false error on new const assignment (#4098). [Tudor Timi] * Fix false ENUMVALUE on expressions and arrays. * Fix unnecessary verilated_std.sv waivers in --waiver-output. diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 962af7e9f..849eb393b 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -5287,6 +5287,8 @@ private: // Function hasn't been widthed, so make it so. // Would use user1 etc, but V3Width called from too many places to spend a user nodep->doingWidth(true); + VL_RESTORER(m_funcp); + VL_RESTORER(m_ftaskp); m_ftaskp = nodep; // First width the function variable, as if is a recursive function we need data type if (nodep->fvarp()) userIterate(nodep->fvarp(), nullptr); @@ -5306,8 +5308,6 @@ private: nodep->didWidth(true); nodep->doingWidth(false); - m_funcp = nullptr; - m_ftaskp = nullptr; if (nodep->dpiImport() && !nodep->dpiOpenParent() && markHasOpenArray(nodep)) { nodep->dpiOpenParentInc(); // Mark so V3Task will wait for a child to build calling // func diff --git a/test_regress/t/t_class_new.v b/test_regress/t/t_class_new.v index f15328470..9d625c5a5 100644 --- a/test_regress/t/t_class_new.v +++ b/test_regress/t/t_class_new.v @@ -7,8 +7,13 @@ class ClsNoArg; const int imembera; // Ok for new() to assign to a const function new(); + int other = other_func(); imembera = 5; + if (other != 6) $stop; endfunction : new + function int other_func(); + return 6; + endfunction endclass class ClsArg;