Add regression tests for shadowing class properties

Check that class properties can be shadowed by local symbols in class
methods and also check that a package scoped identifier with the same name
as class property can be accessed in a class method.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-12-22 21:51:29 -08:00
parent 07e20376d7
commit 4cc3c7b08f
4 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,25 @@
// Check that class properties can be shadowed by a local symbol
module test;
class C;
int x = 0;
task check;
int x; // This should shadow the class property
x = 10;
if (this.x == 0 && x === 10) begin
$display("PASSED");
end else begin
$display("FAILED");
end
endtask
endclass
initial begin
C c;
c = new;
c.check;
end
endmodule

View File

@ -0,0 +1,28 @@
// Check that it is possible to access a package scoped identifier of the same
// name of a class property inside a class method
package P;
int x = 10;
endpackage
module test;
class C;
int x = 0;
task check;
if (P::x === 10) begin
$display("PASSED");
end else begin
$display("FAILED");
end
endtask
endclass
initial begin
C c;
c = new;
c.check;
end
endmodule

View File

@ -584,6 +584,8 @@ sv_class_method_lt_static2 CE,-g2009 ivltests
sv_class_method_signed1 normal,-g2009 ivltests
sv_class_method_signed2 normal,-g2009 ivltests
sv_class_method_var_init normal,-g2009 ivltests
sv_class_prop_shadow1 normal,-g2009 ivltests
sv_class_prop_shadow2 normal,-g2009 ivltests
sv_class_property_signed1 normal,-g2009 ivltests
sv_class_property_signed2 normal,-g2009 ivltests
sv_class_property_signed3 normal,-g2009 ivltests

View File

@ -432,6 +432,8 @@ sv_class_method_default2 CE,-g2009 ivltests
sv_class_method_signed1 CE,-g2009,-pallowsigned=1 ivltests
sv_class_method_signed2 CE,-g2009,-pallowsigned=1 ivltests
sv_class_method_var_init CE,-g2009,-pallowsigned=1 ivltests
sv_class_prop_shadow1 CE,-g2009 ivltests
sv_class_prop_shadow2 CE,-g2009 ivltests
sv_class_property_signed1 CE,-g2009,-pallowsigned=1 ivltests
sv_class_property_signed2 CE,-g2009,-pallowsigned=1 ivltests
sv_class_property_signed3 CE,-g2009,-pallowsigned=1 ivltests