My question is regarding using $cast in SV. If you search for the word cast in the code below, I have on purpose added a '!' to check for unsuccessful casting. In the event of unsuccessful cast, I wanted to see what happens when a call is made to bobsquare.bob(); I am surprised that at time=1ms when call_bob is called with the handle to polygon 'p', the function 'bob' in square class is called to perform the display statements. How can that be possible? I ran with Cadence's irun and debugged with the SV class browser and see that at time=1ms, bobsquare is not even allocated mem space and has NULL as pointer. Thanks!
class figure;
endclass
class polygon extends figure;
virtual function void draw();
$display("polygon::draw");
endfunction
endclass
class square extends polygon;
virtual function void draw();
$display("square::draw");
endfunction
function void compute_area();
$display("square::compute_area");
endfunction
function void bob();
$display("square::I am bob");
$display("%t", $realtime);
endfunction
endclass
program top;
polygon p;
square s;
initial begin
s = new();
p = new();
#1ms;
call_bob(p);
#1ms;
call_bob(s);
end // initial begin
task call_bob(figure generic_ref_figure);
square bobsquare;
if (!($cast(bobsquare, generic_ref_figure)))
bobsquare.bob();
endtask // call_bob
endprogram