Add regression test for wildcard import in class copy construction

Check that class copy construction in a nested scope activates a wildcard
package import and resolves the imported source. Check that construction in
the enclosing scope still resolves the same-named local source.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-08-02 15:32:19 -07:00
parent d05b13b604
commit 2556b5f073
3 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,46 @@
// Check that class copy construction activates a wildcard package import.
package p;
class C;
integer value;
function new(integer value);
this.value = value;
endfunction
endclass
C source = new(42);
endpackage
module test;
p::C source = new(1);
p::C copy_before;
p::C copy_after;
reg failed;
`define check(val, exp) \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, \
`"val`", exp, val); \
failed = 1'b1; \
end
initial begin
failed = 1'b0;
copy_before = new source;
begin : imported_scope
import p::*;
copy_after = new source;
end
`check(copy_before.value, 1);
`check(copy_after.value, 42);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -399,6 +399,7 @@ sv_module_port3 vvp_tests/sv_module_port3.json
sv_module_port4 vvp_tests/sv_module_port4.json
sv_net_array_decl_assign vvp_tests/sv_net_array_decl_assign.json
sv_net_decl_assign vvp_tests/sv_net_decl_assign.json
sv_package_import_copy_new vvp_tests/sv_package_import_copy_new.json
sv_package_import_order_dotstar vvp_tests/sv_package_import_order_dotstar.json
sv_package_import_order_explicit vvp_tests/sv_package_import_order_explicit.json
sv_package_import_order_typedef vvp_tests/sv_package_import_order_typedef.json

View File

@ -0,0 +1,9 @@
{
"type" : "normal",
"source" : "sv_package_import_copy_new.v",
"iverilog-args" : [ "-g2005-sv" ],
"vlog95" : {
"__comment" : "Class scopes and the new operator are not supported",
"type" : "CE"
}
}