Add regression tests for class compatibility
Check that it is possible to assign an object to another object that is of a type of any of its base classes. Also check that an error is reported if this is not the case. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
9b68c5776b
commit
4cfba91d65
|
|
@ -0,0 +1,31 @@
|
|||
// Check that an object can be assigned to a variable of its base class type
|
||||
|
||||
module test;
|
||||
|
||||
class B;
|
||||
int x;
|
||||
|
||||
task t;
|
||||
$display("PASSED");
|
||||
endtask
|
||||
endclass
|
||||
|
||||
class C extends B;
|
||||
int y;
|
||||
|
||||
task t;
|
||||
$display("FAILED");
|
||||
endtask
|
||||
endclass
|
||||
|
||||
B b;
|
||||
C c;
|
||||
|
||||
initial begin
|
||||
c = new;
|
||||
b = c;
|
||||
|
||||
b.t;
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Check that an object can be assigned to a variable of base class across more
|
||||
// than one hierarchy level
|
||||
|
||||
module test;
|
||||
|
||||
class B;
|
||||
int x;
|
||||
|
||||
task t;
|
||||
$display("PASSED");
|
||||
endtask
|
||||
endclass
|
||||
|
||||
class C extends B;
|
||||
int y;
|
||||
|
||||
task t;
|
||||
$display("FAILED");
|
||||
endtask
|
||||
endclass
|
||||
|
||||
class D extends C;
|
||||
int z;
|
||||
|
||||
task t;
|
||||
$display("FAILED");
|
||||
endtask
|
||||
endclass
|
||||
|
||||
B b;
|
||||
D d;
|
||||
|
||||
initial begin
|
||||
d = new;
|
||||
b = d;
|
||||
|
||||
b.t;
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Check that an error is reported when trying to assign an object to variable
|
||||
// of an unrelated class type
|
||||
|
||||
module test;
|
||||
|
||||
class B;
|
||||
int x;
|
||||
endclass
|
||||
|
||||
class C;
|
||||
int y;
|
||||
endclass
|
||||
|
||||
B b;
|
||||
C c;
|
||||
|
||||
initial begin
|
||||
c = new;
|
||||
b = c; // This should fail, both classes are unrelated
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Check that an error is reported when trying when trying to assign an object
|
||||
// of a base class to a variable of a inherited class.
|
||||
|
||||
module test;
|
||||
|
||||
class B;
|
||||
int x;
|
||||
endclass
|
||||
|
||||
class C extends B;
|
||||
int y;
|
||||
endclass
|
||||
|
||||
B b;
|
||||
C c;
|
||||
|
||||
initial begin
|
||||
b = new;
|
||||
c = b; // This should fail, B is a base class of C
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// Check that an error is reported when trying to assign an object to a variable
|
||||
// that shares a common base class but is not directly related.
|
||||
|
||||
module test;
|
||||
|
||||
class B;
|
||||
int x;
|
||||
endclass
|
||||
|
||||
class C extends B;
|
||||
int y;
|
||||
endclass
|
||||
|
||||
class D extends B;
|
||||
int z;
|
||||
endclass
|
||||
|
||||
C c;
|
||||
D d;
|
||||
|
||||
initial begin
|
||||
c = new;
|
||||
d = c; // This should fail, both C and D inherit from B, but there is no
|
||||
// direct relationship.
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -531,6 +531,11 @@ sv_class21 normal,-g2009 ivltests
|
|||
sv_class22 normal,-g2009 ivltests
|
||||
sv_class23 normal,-g2009 ivltests
|
||||
sv_class24 normal,-g2009 ivltests
|
||||
sv_class_compat1 normal,-g2009 ivltests
|
||||
sv_class_compat2 normal,-g2009 ivltests
|
||||
sv_class_compat_fail1 CE,-g2009 ivltests
|
||||
sv_class_compat_fail2 CE,-g2009 ivltests
|
||||
sv_class_compat_fail3 CE,-g2009 ivltests
|
||||
sv_class_constructor1 normal,-g2009 ivltests
|
||||
sv_class_constructor_fail CE,-g2009 ivltests
|
||||
sv_class_empty_item normal,-g2009 ivltests
|
||||
|
|
|
|||
|
|
@ -404,6 +404,8 @@ sv_class21 CE,-g2009 ivltests
|
|||
sv_class22 CE,-g2009 ivltests
|
||||
sv_class23 CE,-g2009 ivltests
|
||||
sv_class24 CE,-g2009 ivltests
|
||||
sv_class_compat1 CE,-g2009 ivltests
|
||||
sv_class_compat2 CE,-g2009 ivltests
|
||||
sv_class_constructor1 CE,-g2009 ivltests
|
||||
sv_class_empty_item CE,-g2009 ivltests
|
||||
sv_class_extends_scoped CE,-g2009 ivltests
|
||||
|
|
|
|||
Loading…
Reference in New Issue