Add regression tests for typed constructor calls

Check that typed constructors calls are supported. Also check various
invalid usages of typed constructor calls and check that an error is
reported.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-12-18 15:00:10 -08:00
parent df82410a37
commit 6334839406
9 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,16 @@
// Check that typed constructor calls are supported.
module test;
class C;
function new;
$display("PASSED");
endfunction
endclass
initial begin
C c;
c = C::new;
end
endmodule

View File

@ -0,0 +1,30 @@
// Check that typed constructor calls are supported when assigning to an
// variable of a base class type.
module test;
class B;
int x = 0;
task check;
if (x === 10) begin
$display("PASSED");
end else begin
$display("FAILED");
end
endtask
endclass
class C extends B;
function new;
x = 10;
endfunction
endclass
initial begin
B b;
b = C::new;
b.check;
end
endmodule

View File

@ -0,0 +1,19 @@
// Check that typed constructor calls are supported when the type is a typedef
// of a class type.
module test;
class C;
function new;
$display("PASSED");
endfunction
endclass
typedef C T;
initial begin
T c;
c = T::new;
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that an error is reported when using a typed constructor call to assign
// to a class that is not a base class.
module test;
class B;
endclass
class C;
endclass
initial begin
B b;
b = C::new; // This should fail, B is not a base class of C
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,19 @@
// Check that an error is reported when using a typed constructor call to assign
// to a class that is an inherited class.
module test;
class B;
endclass
class C extends B;
endclass
initial begin
C c;
c = B::new; // This should fail, B is a base class of C, but C is not a
// base class of B.
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,22 @@
// Check that an error is reported when using a typed constructor call to assign
// to a class that has a common base class, but is not directly related.
module test;
class B;
endclass
class C extends B;
endclass
class D extends B;
endclass
initial begin
D d;
d = C::new; // This should fail, C and D share a common base class, but are
// not compatible
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,17 @@
// Check that an error is reported when trying to use a typed constructor call
// with a type that is not a class.
module test;
class C;
endclass
typedef int T;
initial begin
C c;
c = T::new; // This should fail, T is not a class
$display("FAILED");
end
endmodule

View File

@ -561,6 +561,13 @@ sv_class_localparam normal,-g2009 ivltests
sv_class_new_fail1 CE,-g2009 ivltests
sv_class_new_fail2 CE,-g2009 ivltests
sv_class_new_init normal,-g2009 ivltests
sv_class_new_typed1 normal,-g2009 ivltests
sv_class_new_typed2 normal,-g2009 ivltests
sv_class_new_typed3 normal,-g2009 ivltests
sv_class_new_typed_fail1 CE,-g2009 ivltests
sv_class_new_typed_fail2 CE,-g2009 ivltests
sv_class_new_typed_fail3 CE,-g2009 ivltests
sv_class_new_typed_fail4 CE,-g2009 ivltests
sv_class_in_module_decl normal,-g2009 ivltests
sv_class_method_call_void normal,-g2009 ivltests
sv_class_method_default1 normal,-g2009 ivltests

View File

@ -416,6 +416,9 @@ sv_class_empty_item CE,-g2009 ivltests
sv_class_extends_scoped CE,-g2009 ivltests
sv_class_localparam CE,-g2009 ivltests
sv_class_new_init CE,-g2009 ivltests
sv_class_new_typed1 CE,-g2009 ivltests
sv_class_new_typed2 CE,-g2009 ivltests
sv_class_new_typed3 CE,-g2009 ivltests
sv_class_in_module_decl CE,-g2009 ivltests
sv_class_method_call_void CE,-g2009 ivltests
sv_class_method_default1 CE,-g2009 ivltests