How to solve the issue about the output data in a task

task read_data(logic[31:0] addr, output logic [31:0] data);
   my_handle hdl;
   hdl.get_data(data);
endtask

class my_handle extends uvm_component;
  logic [31:0] buf[$];
  task get_data(output logic [31:0] data);
    wait(buf.size);
    data = buf.pop_front();
  endtask
endclass

in my test, I tried to call the task read_data(), but it failed at below error.

Error-[AIORPML] Illegal argument to port
Argument to inout/output/ref port must be an expression that is valid on the left-hand side of a procedural assignment.

Please kindly give me a help. Thank you

In reply to zz8318:

It is not clear from your question which line is causing the error. Could it be the line that calls read_data() which you did not show?

In reply to dave_59:

Hi Dave, sorry for that. Let me paste the error line here.

in my test I created a task (named wait_to_idle) as shown below.

task my_test::wait_to_idle();
logic [31:0] data;
logic [31:0] addr = 'hxxxx;
read_data(addr, data); <== here is the error line

endtask

In reply to zz8318:

I see nothing wrong with the code you’ve shown. Check for typos.

In reply to dave_59:

I feel a little strange about the error information.

Error-[AIORPML] Illegal argument to port
Argument to inout/output/ref port must be an expression that is valid on the left-hand side of a procedural assignment.

Does it mean we need to make sure that the argument tagged with the output direction is required to used in the left-hand side of assignment ?

In reply to zz8318:

Yes. The task does a procedural assignment to the actual output argument upon leaving the task.

So if you have

read_data(addr, somearg ); 

You must also be able to do

somearg = value; 

In reply to dave_59:

I put the code " somearg = value " in another task which is inside class my_handle. Is that correct ??

class my_handle extends uvm_component;
logic [31:0] buf[$];
task get_data(output logic [31:0] data);
wait(buf.size);
data = buf.pop_front(); <== here
endtask
endclass

In reply to zz8318:

No, I was referring to data in the task wait_to_idle