Sequence item inheritance error

Hi,
i am trying to understand the use of inheritance while defining a sequence item.
I have a base sequence with few objects as below

 class base_seq_item extends uvm_sequence_item
     rand logic command;      // Read/write
     rand logic [7:0] data;   // input data
     rand logic [7:0] address // write/read address 

     function new ();
       super.new();
     endfunction

     `uvm_objects_utils_begin(base_seq_item)
     `uvm_field_int(command,UVM_ALL_ON)
     `uvm_field_int(data,UVM_ALL_ON)
     `uvm_field_int(address,UVM_ALL_ON)
     `uvm_objects_utils_end

   endclass
 
   class write_seq_item extends base_seq_item
     constraint write_seq {
             command = 0;
     }
     task display();
       this.sprint;
     endtask
   endclass

   class wr_seq extends uvm_sequence #(write_seq_item)
     write_seq_item req;
     
     task body();
       `uvm_do_with(req,{data=0xFF};{address=0x80};);
     endtask

     function new ();
       super.new();
     endfunction

   endclass

Here i am getting the below error:
*E,BCLCST (…/testbench/sequence/wr_seq.sv): Invalid cast: a value with the class datatype ‘spi_pkg::base_seq_item’ cannot be assigned to a class variable with the datatype ‘spi_pkg::write_seq_item’.
*E,TRNULLID: Null point dereference

can i not randomize a baseclass variable with extended class handle?

In reply to manasa-n:

There are too many typos in your example to know what might be wrong. Please be more careful in copy/pasting your code. Also, point out the exact line causing the error.

In reply to dave_59:
Hi,
Thanks for your reply.
actually it was not letting me copy paste, so i have re-typed everything here.

The issue is that i have extended a sequence_item(write_seq_item) from a base sequence_item(base_seq_item) and in write_seq_item i just have few constraint.

When in sequence (parameterized with type of write_seq_item) i try to randomize using uvm_do_with macro i get the below error:

*E,BCLCST (…/testbench/sequence/wr_seq.sv): Invalid cast: a value with the class datatype ‘base_seq_item’ cannot be assigned to a class variable with the datatype ‘write_seq_item’.
*E,TRNULLID: Null point dereference

im not sure why i get this.

In reply to manasa-n:

In reply to dave_59:
Hi,
Thanks for your reply.
actually it was not letting me copy paste, so i have re-typed everything here.
The issue is that i have extended a sequence_item(write_seq_item) from a base sequence_item(base_seq_item) and in write_seq_item i just have few constraint.
When in sequence (parameterized with type of write_seq_item) i try to randomize using uvm_do_with macro i get the below error:
*E,BCLCST (…/testbench/sequence/wr_seq.sv): Invalid cast: a value with the class datatype ‘base_seq_item’ cannot be assigned to a class variable with the datatype ‘write_seq_item’.
*E,TRNULLID: Null point dereference
im not sure why i get this.

In your code I don’t see any call to type_id::create() for the sequence item, you have a handle to your write_seq_item which is null that is why you get null point derefence error, The code you posted as Dave mentioned has too many typos so I’m not sure if the actual code you are using has the type_id::create() to actually allocate the seq item.

HTH,

-R

In reply to rgarcia07:

In reply to manasa-n:
In your code I don’t see any call to type_id::create() for the sequence item, you have a handle to your write_seq_item which is null that is why you get null point derefence error, The code you posted as Dave mentioned has too many typos so I’m not sure if the actual code you are using has the type_id::create() to actually allocate the seq item.
HTH,
-R

I am using `uvm_do_with macro it calls the create method internally.

In reply to manasa-n:

Make sure that write_seq_item is registered with the factory using `uvm_object_utils.

In reply to cgales:

its registered.

Hi Manasa,
I have tried your code in one of my examples.It is working for me. You can take a look.It seems like extended sequence item was not registered in the code provided by you.


class base_seq_item extends uvm_sequence_item;
     rand logic command;      // Read/write
     rand logic [7:0] data;   // input data
     rand logic [7:0] address; // write/read address 
 
     function new();
       super.new();
     endfunction
 
     `uvm_object_utils_begin(base_seq_item)
       `uvm_field_int(command,UVM_ALL_ON)
       `uvm_field_int(data,UVM_ALL_ON)
       `uvm_field_int(address,UVM_ALL_ON)
     `uvm_object_utils_end
 
   endclass
 
   class write_seq_item extends base_seq_item;
     `uvm_object_utils(write_seq_item)

     constraint write_seq {
             command inside {0};
     }
     task display();
       this.sprint;
     endtask
   endclass
 
   class wr_seq extends uvm_sequence #(write_seq_item);
     write_seq_item req;
 
     task body();
       `uvm_do_with(req,
                   {data=='hFF;
                   address=='h80;
                    })
     endtask      
   endclass

Let me know if you still face any issue with this.

Regards,
Dhaval