From 6334839406a235868603d59fdf91def9b1e57494 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 18 Dec 2022 15:00:10 -0800 Subject: [PATCH] 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 --- ivtest/ivltests/sv_class_new_typed1.v | 16 ++++++++++++ ivtest/ivltests/sv_class_new_typed2.v | 30 ++++++++++++++++++++++ ivtest/ivltests/sv_class_new_typed3.v | 19 ++++++++++++++ ivtest/ivltests/sv_class_new_typed_fail1.v | 18 +++++++++++++ ivtest/ivltests/sv_class_new_typed_fail2.v | 19 ++++++++++++++ ivtest/ivltests/sv_class_new_typed_fail3.v | 22 ++++++++++++++++ ivtest/ivltests/sv_class_new_typed_fail4.v | 17 ++++++++++++ ivtest/regress-sv.list | 7 +++++ ivtest/regress-vlog95.list | 3 +++ 9 files changed, 151 insertions(+) create mode 100644 ivtest/ivltests/sv_class_new_typed1.v create mode 100644 ivtest/ivltests/sv_class_new_typed2.v create mode 100644 ivtest/ivltests/sv_class_new_typed3.v create mode 100644 ivtest/ivltests/sv_class_new_typed_fail1.v create mode 100644 ivtest/ivltests/sv_class_new_typed_fail2.v create mode 100644 ivtest/ivltests/sv_class_new_typed_fail3.v create mode 100644 ivtest/ivltests/sv_class_new_typed_fail4.v diff --git a/ivtest/ivltests/sv_class_new_typed1.v b/ivtest/ivltests/sv_class_new_typed1.v new file mode 100644 index 000000000..789f870cb --- /dev/null +++ b/ivtest/ivltests/sv_class_new_typed1.v @@ -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 diff --git a/ivtest/ivltests/sv_class_new_typed2.v b/ivtest/ivltests/sv_class_new_typed2.v new file mode 100644 index 000000000..77c459cb3 --- /dev/null +++ b/ivtest/ivltests/sv_class_new_typed2.v @@ -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 diff --git a/ivtest/ivltests/sv_class_new_typed3.v b/ivtest/ivltests/sv_class_new_typed3.v new file mode 100644 index 000000000..c725ea3ac --- /dev/null +++ b/ivtest/ivltests/sv_class_new_typed3.v @@ -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 diff --git a/ivtest/ivltests/sv_class_new_typed_fail1.v b/ivtest/ivltests/sv_class_new_typed_fail1.v new file mode 100644 index 000000000..8aac5ff6b --- /dev/null +++ b/ivtest/ivltests/sv_class_new_typed_fail1.v @@ -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 diff --git a/ivtest/ivltests/sv_class_new_typed_fail2.v b/ivtest/ivltests/sv_class_new_typed_fail2.v new file mode 100644 index 000000000..d6b88ecb7 --- /dev/null +++ b/ivtest/ivltests/sv_class_new_typed_fail2.v @@ -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 diff --git a/ivtest/ivltests/sv_class_new_typed_fail3.v b/ivtest/ivltests/sv_class_new_typed_fail3.v new file mode 100644 index 000000000..6c8827354 --- /dev/null +++ b/ivtest/ivltests/sv_class_new_typed_fail3.v @@ -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 diff --git a/ivtest/ivltests/sv_class_new_typed_fail4.v b/ivtest/ivltests/sv_class_new_typed_fail4.v new file mode 100644 index 000000000..63181ccfe --- /dev/null +++ b/ivtest/ivltests/sv_class_new_typed_fail4.v @@ -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 diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 0bd00a1aa..c52d24597 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -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 diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index 8a99ce8d0..df24c1a67 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -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