$cast failed using parameterised uvm_sequence_item class

In reply to Po:

Yes completely agree with you you do not need to create (my worry was that it was not sent/created or so hence a null pointer was used).

Having said that my only concern is now basically referring to the bus_item is not basically the same type as the one used for the casting in other words:

  • The item sent to the monitor is: extended_seq_item #(config_class)
  • The item grabbed by the predictor is extended_seq_item #(config_class)
  • But the item sent during the REG transaction is not the same type or not parametrised or simply the param is different (the casting is specialised something like the config_db)

For example:


class pc;
  function void display();
    $display("Parent class has no parameter to display");
  endfunction
endclass

class cc#(int Val=0) extends pc;
  function void display();
    super.display();
    $display("Parameter = %0d",Val);
  endfunction
endclass

module top;
  initial begin
    pc p;
    cc #(11) c = new();
    cc #(10) c1;
    p = c;         
    $cast(c1,p); 
    c1.display(); 
  end
endmodule

// this will result in 
/*
Error-[DCF] Dynamic cast failed
testbench.sv, 23
  Casting of source class type '\cc#(11) ' to destination class type '\cc#(10)
  ' failed due to type mismatch.
  Please ensure matching types for dynamic cast
*/

// This instead will Pass
module top;
  initial begin
    pc p;
    cc #(11) c = new();
    cc #(11) c1;
    p = c;         
    $cast(c1,p); 
    c1.display(); 
  end
endmodule

Sorry for the naming conventions it was just to be quick.

Regards