The bit-stream casting in SystemVerilog for arrays and structs does not seem very safe.
For example, the following casting issue will only be caught at runtime (which could be hours into the simulation):
bit [31:0] bit_queue[$];
logic [31:0] logic_array[5];
for (int i = 0; i < 10; i++) begin
bit_queue[i] = $urandom;
end
if (catch_issue) begin
typedef logic [31:0] logic_array_t [5];
logic_array = logic_array_t'(bit_queue); // <-- ISSUE
end
Is there a proper "safe" procedure for doing bit-stream casting? Where any issues could be caught at compile time or safely handled at runtime? Or is the language broken in this case?
Example code above on EDA Playground: http://www.edaplayground.com/x/2tp