diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 02759c300..9a50ac9bb 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -183,6 +183,7 @@ Pengcheng Xu Peter Debacker Peter Horvath Peter Monsson +Petr Nohavica Philip Axer Philipp Wagner Pierre-Henri Horrein diff --git a/src/V3Width.cpp b/src/V3Width.cpp index acc3b0647..1b23f494a 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -4802,7 +4802,12 @@ class WidthVisitor final : public VNVisitor { patp = VN_AS(patp->nextp(), PatMember)) { patp->dtypep(arrayDtp->subDTypep()); AstNodeExpr* const valuep = patternMemberValueIterate(patp); - AstNode* keyp = patp->keyp(); + AstNode* keyp; + if (patp->varrefp()) { + keyp = patp->varrefp(); + } else { + keyp = patp->keyp(); + } if (!keyp) { patp->v3error("Missing pattern key (need an expression then a ':')"); keyp = new AstConst{nodep->fileline(), AstConst::Signed32{}, 0}; diff --git a/test_regress/t/t_assoc_enum.py b/test_regress/t/t_assoc_enum.py new file mode 100755 index 000000000..f989a35fb --- /dev/null +++ b/test_regress/t/t_assoc_enum.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_assoc_enum.v b/test_regress/t/t_assoc_enum.v new file mode 100644 index 000000000..485e3205f --- /dev/null +++ b/test_regress/t/t_assoc_enum.v @@ -0,0 +1,44 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2025 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +`define stop $stop +`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0x exp=%0x (%s !== %s)\n", `__FILE__,`__LINE__, (gotv), (expv), `"gotv`", `"expv`"); `stop; end while(0); +`define checks(gotv,expv) do if ((gotv) != (expv)) begin $write("%%Error: %s:%0d: got='%s' exp='%s'\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0); + +class X; + typedef enum int { + INITIAL, RUNNING, SUSPENDED, COMPLETING, DONE + } state_t; + + static string state_names[state_t] = '{ + INITIAL: "INITIAL", + RUNNING: "RUNNING", + SUSPENDED: "SUSPENDED", + COMPLETING: "COMPLETING", + DONE: "DONE" + }; + protected state_t state; + + function new(); + this.state = INITIAL; + `checks(state_names[this.state], "INITIAL"); + this.state = RUNNING; + `checks(state_names[this.state], "RUNNING"); + endfunction + +endclass + +module t;/*AUTOARG*/ + + +initial begin + X x = new; + $finish; +end + + + +endmodule