module
int i;
initial
begin
mailbox mb;
mb = new(2);
mb.put(“WORD”);
mb.get(i); //expect a run time error
end
endmodule
In the above code I expect a run time error as there is a type mismatch while getting the data from the mailbox.But when I display it seem to be like the ASCII value is printed.The above code is simulated in questa(10.1b).
The reason you aren’t getting an error is because your mailbox is typeless. With this mailbox, you can put() and get() items of any type. As you have noticed, this can lead to some unexpected behavior if you don’t manage the types correctly.
It is highly recommended that you only use typed mailboxes which will enforce the datatypes used in put() and get().
module test;
int i;
initial
begin
mailbox#(string) mb; // Note type of mailbox
mb = new(2);
mb.put("WORD");
mb.get(i); //expect a run time error
end
endmodule
When run:
** Error: (vsim-8754) test.sv(8): Actual output arg. of type ‘int’ for formal ‘message’ of ‘get’ is not compatible with the formal’s type ‘string’.