Files
iverilog/ivtest/ivltests/sv_class_method_default1.v
T
Lars-Peter Clausen 0aef9326ca Add regression test for class method argument defaults
Check that default values for class methods are handled correctly and it is
possible to omit any argument. Check it for both functions and tasks.

Signed-off-by: Lars-Peter Clausen <[email protected]>
2022-10-05 08:49:25 +02:00

42 lines
867 B
Verilog

// Check that default values on function methods are supported and it is
// possible to omit any of the arguments.
class C;
function integer f(integer x = 1, integer y = 2, integer z = 3);
return x + y + z;
endfunction
endclass
module test;
C c = new;
bit failed = 1'b0;
`define check(expr, val) \
if (expr !== val) begin \
$display("FAILED. %s, expected %d, got %d", `"expr`", val, expr); \
failed = 1'b1; \
end
initial begin
`check(c.f(), 6);
`check(c.f(4), 9);
`check(c.f(4, ), 9);
`check(c.f(4, , ), 9);
`check(c.f(4, 6), 13);
`check(c.f(4, 6, ), 13);
`check(c.f(4, , 8), 14);
`check(c.f(4, 6, 8), 18);
`check(c.f(, 6), 10);
`check(c.f(, 6, ), 10);
`check(c.f(, 6 ,8), 15);
`check(c.f(, , 8), 11);
if (!failed) begin
$display("PASSED");
end
end
endmodule