Problem with .randomize "with"; why do the attribute names need to match?

Hi everyone, thanks in advance for your help.

I’m working with a 3rd party IP and am trying to randomize a transaction class. I get a runtime error as follows:

** Fatal: Illegal unpacked assignment to type ‘bit’ from packed type ‘bit[31:0]$’.

If I rename my local variable to match the name of the class variables, I no longer get this error. Why?

My code looks basically like this.

class sequence …
bit [AXI4_WDATA_WIDTH-1:0] data_words;

task body();

if(!write_item.randomize() with {
addr == local::address; // must use local here.
foreach(local::data_words[j])
data_words[j] == local::data_words[j];
}) `uvm_error(“MYERR”, “This is a randomize error”);

    finish_item( write_item );

The above code works without error.

If I rename things to be the following, I get the error:
class sequence …
bit [AXI4_WDATA_WIDTH-1:0] write_data_words;

task body();

if(!write_item.randomize() with {
addr == local::address; // must use local here.
foreach(local::write_data_words[j])
data_words[j] == local::write_data_words[j];
}) `uvm_error(“MYERR”, “This is a randomize error”);

    finish_item( write_item );

The write_item class has what I believe to be the correct matching type:
rand bit [((AXI4_WDATA_WIDTH) - 1):0] data_words ;

Question
Why can’t I use a different name than the name inside the item being randomized? I thought my ‘local’ scope allow me to specify any local name. The error suggests that the LHS is being interpreted as a bit in the failing case and I assume not a bit, but the proper array size in the passing case.

When used with matching names, my write transaction appears to work correctly.

Thanks for sharing your insight and knowledge, I appreciate it.
Brian

In reply to jnbkeller:

It’s hard to say what might be going wrong with the limited code shown. Most of these kinds of problems coming from randomize() with {} are because you are not picking up the variable you think you should be.

I would put a $display($typename(write_item.data_words)) just before the randomization (or use your debugging tool to find out if it is picking up the correct variable.

In reply to dave_59:

thanks Dave, At least it ‘seems’ that what I’m doing is ‘doable’. I’ll try your display option to try and debug it further.

I’ve got a workaround right now, so I’ll close this out with your recommendation on debugging because I don’t want to leave it open waiting till I get back to it.

Thanks again for your help and suggestions.
Brian