Add regression tests for class properties shadowing type names

Check that a class property can have the same name as a type declared in
an outer scope, or a type imported through a wildcard import. Also check
that a class property can have the same name as the class itself.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-06-27 10:01:57 -07:00
parent dc66f2fe7e
commit 5364f11d16
7 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// Check that a class property can have the same name as the class.
module test;
bit failed = 1'b0;
`define check(val, exp) do \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
class C;
int C;
function int get;
return C;
endfunction
endclass
C obj;
initial begin
obj = new;
obj.C = 23;
`check(obj.get(), 23);
`check(obj.C, 23);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,39 @@
// Check that a class property can have the same name as an outer type.
module test;
typedef int T;
bit failed = 1'b0;
`define check(val, exp) do \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
class C;
int T;
function int get;
return T;
endfunction
endclass
C obj;
initial begin
obj = new;
obj.T = 11;
`check(obj.get(), 11);
`check(obj.T, 11);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,45 @@
// Check that a class property can shadow a wildcard-imported type name.
package P;
typedef int T;
endpackage
module test;
import P::*;
bit failed = 1'b0;
`define check(val, exp) do \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
class C;
int T;
function int get;
return T;
endfunction
endclass
C obj;
initial begin
obj = new;
obj.T = 47;
`check(obj.get(), 47);
`check(obj.T, 47);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -279,8 +279,11 @@ sv_chained_constructor4 vvp_tests/sv_chained_constructor4.json
sv_chained_constructor5 vvp_tests/sv_chained_constructor5.json sv_chained_constructor5 vvp_tests/sv_chained_constructor5.json
sv_class_prop_assign_op1 vvp_tests/sv_class_prop_assign_op1.json sv_class_prop_assign_op1 vvp_tests/sv_class_prop_assign_op1.json
sv_class_prop_assign_op2 vvp_tests/sv_class_prop_assign_op2.json sv_class_prop_assign_op2 vvp_tests/sv_class_prop_assign_op2.json
sv_class_prop_class_name vvp_tests/sv_class_prop_class_name.json
sv_class_prop_logic vvp_tests/sv_class_prop_logic.json sv_class_prop_logic vvp_tests/sv_class_prop_logic.json
sv_class_prop_packed_dims vvp_tests/sv_class_prop_packed_dims.json sv_class_prop_packed_dims vvp_tests/sv_class_prop_packed_dims.json
sv_class_prop_type_name vvp_tests/sv_class_prop_type_name.json
sv_class_prop_wildcard_type_name vvp_tests/sv_class_prop_wildcard_type_name.json
sv_class_prop_nest_darray1 vvp_tests/sv_class_prop_nest_darray1.json sv_class_prop_nest_darray1 vvp_tests/sv_class_prop_nest_darray1.json
sv_class_prop_nest_obj1 vvp_tests/sv_class_prop_nest_obj1.json sv_class_prop_nest_obj1 vvp_tests/sv_class_prop_nest_obj1.json
sv_class_prop_nest_real1 vvp_tests/sv_class_prop_nest_real1.json sv_class_prop_nest_real1 vvp_tests/sv_class_prop_nest_real1.json

View File

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

View File

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

View File

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