Fix `local::` false error in randomize() with on parameterized class (#6680) (#7293)`

This commit is contained in:
Yilou Wang 2026-03-20 15:25:46 +01:00 committed by GitHub
parent a8bccab8e6
commit b71abb0032
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 83 additions and 1 deletions

View File

@ -4663,7 +4663,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
}
if (nodep->name() == "local::") {
if (!m_randSymp) {
if (!m_randSymp && !m_randMethodCallp) {
nodep->v3error("Illegal 'local::' outside 'randomize() with'"
" (IEEE 1800-2023 18.7.1)");
m_ds.m_dotErr = true;

View File

@ -0,0 +1,21 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# 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-FileCopyrightText: 2026 Wilson Snyder
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
test.scenarios('simulator')
if not test.have_solver:
test.skip("No constraint solver installed")
test.compile()
test.execute()
test.passes()

View File

@ -0,0 +1,61 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain.
// SPDX-FileCopyrightText: 2026 PlanV GmbH
// SPDX-License-Identifier: CC0-1.0
// verilog_format: off
`define stop $stop
`define checkd(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0d exp=%0d\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
// verilog_format: on
class item_cls #(type T = int);
rand T value;
endclass
class multi_param_cls #(type T = int, int WIDTH = 8);
rand T data;
rand bit [WIDTH-1:0] mask;
endclass
class driver_cls #(type T = int);
function int do_rand(T val);
item_cls#(T) itemp;
itemp = new();
void'(itemp.randomize() with { value == local::val; });
return (itemp.value == val) ? 32'd1 : 32'd0;
endfunction
endclass
class multi_driver_cls #(type T = int, int WIDTH = 8);
function int do_rand(T val, bit [WIDTH-1:0] m);
multi_param_cls#(T, WIDTH) itemp;
itemp = new();
void'(itemp.randomize() with {
data == local::val;
mask == local::m;
});
return (itemp.data == val && itemp.mask == m) ? 32'd1 : 32'd0;
endfunction
endclass
module t;
initial begin
driver_cls#(int) drvp;
multi_driver_cls#(int, 8) mdrvp;
drvp = new();
mdrvp = new();
repeat (20) begin
`checkd(drvp.do_rand(32'd42), 32'd1)
end
repeat (20) begin
`checkd(mdrvp.do_rand(32'd99, 8'hAB), 32'd1)
end
$write("*-* All Finished *-*\n");
$finish;
end
endmodule