How to separate the namespace between a random-constrained object's member and the calling class' member

I have a sequence simplified as :

class my_seq extends some_base_sequence;
   bit[7:0] exp_val[5];

   task body();
      // loops through each exp_val item for some checks
   endtask
endclass

It is randomized-constrained from another sequence which is simplified as :

class top_seq extends uvm_sequence;
   bit[7:0] exp_val[5];
   my_seq   check_seq;

   task body();
      foreach (exp_val[idx])
         exp_val[idx] = some_val; // basically some calculated value
      check_seq = my_seq::type_id::create("check_seq");
      if (!randomize(check_seq) with {
            foreach (exp_val[idx])
               exp_val[idx] == exp_val[idx];
         })
         `uvm_fatal("Randomization failed")
      else
         check_seq.start(p_sequencer.my_seqr, this);
   endtask
endclass

Now when check_seq is started, the exp_val items are all just 0. It means it didn’t get the values passed to it by the top_seq. Even if I try adding this to give the distinction between the 2 members, the issue is still there.

      if (!randomize(check_seq) with {
            foreach (exp_val[idx]) // also tried this.exp_val in this line
               exp_val[idx] == this.exp_val[idx];
         })

If I change the name of my_seq’s exp_val to something else and do the same in top_seq, then the constraint takes effect. So I’m guessing it’s a ‘same member name’ issue ? In Specman e if I recall there’s a way to do it by adding . to specify the object’s member, but I don’t know how to do it here.

Your class my_seq is not parameterized for a certain sequence_item. It should be something like this:

I have modified the my_seq as it actually extends from another base sequence in my case. But do you mean that my_seq not being parameterized is causing the issue ?

A sequence - with the exception of a virtual sequence - generates sequence_items. And you have to indicate which type they are. I do not know how your base_seq is looking like.

The identifiers in the randomize with {} clause are all local to the object being randomized, including the this keyword. To get back to the local scope of where the call to randomize is located, use local::

if (!randomize(check_seq) with {
            foreach (exp_val[idx]) 
               exp_val[idx] == local::exp_val[idx];
         })

Thanks for your help, but I think this is very far from the issue that I’m trying to resolve. The fact that I mentioned that the constraint is taking effect by only changing the name of its variable means that there’s no issue with my_seq or with any base_seq that it is deriving from.

Thank you so much Dave ! As always, you understand the context of the issues that we face and give solutions that work. Hope to meet you someday :metal: