Can task arguments which are class variables (object handle) be always treated as "pass by ref" type argument?

Hello,

I have a task defined within a class as below

virtual task drive_input (
         string               name,
         int                  prior = -1,
         uvm_sequence_base    parent = null,
         uvm_object           tr     = null, 
         output status_e      status);
        ..........
        tr = env.agent.seqr;//The sequencer is of type uvm_sequencer #(pin_uvi_transfer_c #(1))
         `uvm_info ("", $sformatf("cmp_pos_analog_seq_get_seqr drive_input: tr = %p", tr), UVM_HIGH)//Here I am getting non-null value printed
        ..........
   endtask

And from a sequence (i.e child of uvm_sequence) I am calling the above task as shown below.


uvm_sequencer #(pin_uvi_transfer_c #(1)) tst_cmp_neg_ana_seqr ;

sal.drive_input(
   				.name   ("tst_cmp_neg_analog_seq_get_seqr"),
   				.parent (this),
   				.tr     (tst_cmp_neg_ana_seqr),
   				.status (sal_status));
if(tst_cmp_neg_ana_seqr == null) `uvm_error("","Unable to get tst_cmp_neg_ana_seqr sequencer from SAL")

I get the error “Unable to get tst_cmp_neg_ana_seqr sequencer from SAL” because tst_cmp_neg_ana_seqr is null although the print statement inside drive_input task displays non-null value for tr.
Please let me know if I am missing something here or is this expected result.

In reply to Aryan:

Class variables and object handles are two closely releated bit seperate concepts. A handle is a value representing a reference to a instance of an object. A class variable is simply a place that holds the value of a handle of a particular class type.

The default first argument direction for a task/function is an input passed by value upon entry. Successive argument use the previous direction as the implicit default. So just like the previous parent argument, the tr argument is an input whose value gets passed by value upon entry to the task. You need to make the tr argument an output. Passing by ref creates an unnecessary double reference - see this post.

But once you change the direction to output, you would be downcasting to tst_cmp_neg_ana_seqr from tr, which has the type uvm_sequence_base. So you need to make the formal and actual argument types compatible, and then use $cast.