Add regression test for classes in generate blocks

Check that a class declared in a conditional generate block can be used.
Also check that classes declared in a generate loop get separate class scopes
for each generated instance.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-06-20 17:05:56 -07:00
parent 7934ab9eeb
commit bb8b05bb5d
3 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,50 @@
// Check that classes declared inside generate blocks can be used.
module test;
reg failed;
`define check(val, exp) \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, \
`"val`", exp, val); \
failed = 1'b1; \
end
if (1) begin : g
class C;
int value;
function new(int value);
this.value = value;
endfunction
endclass
C c = new(42);
end
for (genvar i = 0; i < 2; i = i + 1) begin : h
class C;
int value;
function new(int value);
this.value = value + i;
endfunction
endclass
C c = new(10);
end
initial begin
failed = 1'b0;
`check(g.c.value, 42);
`check(h[0].c.value, 10);
`check(h[1].c.value, 11);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -82,6 +82,7 @@ br_gh1258a vvp_tests/br_gh1258a.json
br_gh1258b vvp_tests/br_gh1258b.json
br_gh1286 vvp_tests/br_gh1286.json
br_gh1323 vvp_tests/br_gh1323.json
br_gh1384 vvp_tests/br_gh1384.json
br_gh1385 vvp_tests/br_gh1385.json
br_gh1385a vvp_tests/br_gh1385a.json
br_gh1385b vvp_tests/br_gh1385b.json

View File

@ -0,0 +1,9 @@
{
"type" : "normal",
"source" : "br_gh1384.v",
"iverilog-args" : [ "-g2005-sv" ],
"vlog95" : {
"__comment" : "Classes are not supported",
"type" : "CE"
}
}