Passing queue through sequence_item

I am writing a UVM sequence_item code with queue in it
For each test I am randomizing some variable in seq_item and passing it to driver through sequencer

Following is a dummy code

class seq_item extends uvm_sequence_item;
   function new(string name="seq_item");;
   endfunction : new

  int a,b,c;
  int q[$];
endclass : seq_item
class seq extends uvm_sequence#(seq_item);
   function new(string name="seq");;
   endfunction : new
   seq_item req;
   extern virtual task body();
endclass : seq

task seq :: body(); 
   req = seq_item::type_id::create("req");
    if(!req.randomize() with { req.a == 8'h0;
                              req.b == 8'h5;})
      `uvm_error("SEQ", $sformatf("Randomization Failed in %s", get_name()))

    for(int i=0; req.start_elem_count_UVM+i<=req.final_elem_count_UVM;i++) begin
      req.q[i] = i;
endtask : body

This is my first time using a queue in the Sequence_item and passing it to the driver seq_item_port
Will this work or cause error?

In reply to bachan21:

  1. You aren’t using a queue, you are using a dynamic array.
  2. Before assigning values to a dynamic array, you need to ‘new’ it with the size of the array.
  3. A dynamic array can be randomized as long as the size is constrained appropriately.
  4. Your randomize() call will fail because your sequence_item variables aren’t declared with the ‘rand’ keyword.
  5. A sequence_item can contain any datatype. Why do you think that a dynamic array/queue won’t work?

In reply to cgales:

hi, that was a typo
Thanks for clearing the doubt