# Expression of this type cannot be used to index the array

**URL:** <https://verificationacademy.com/forums/t/expression-of-this-type-cannot-be-used-to-index-the-array/35426>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, randomization-associative-array\
**Created:** [December 6, 2018, 9:17pm UTC](https://verificationacademy.com/forums/t/expression-of-this-type-cannot-be-used-to-index-the-array/35426 "2018-12-06T21:17:59Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![prabhakaran.gunasekaran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/6bbea6/32.png) [@prabhakaran.gunasekaran](https://verificationacademy.com/forums/u/prabhakaran.gunasekaran)\
**Post date:** [December 7, 2018, 6:36am UTC](https://verificationacademy.com/forums/t/expression-of-this-type-cannot-be-used-to-index-the-array/35426/4 "2018-12-07T06:36:25Z")

</div>

_In reply to [desperadorocks](https://verificationacademy.com/forums/t/expression-of-this-type-cannot-be-used-to-index-the-array/35426/3):_

The below code seems working.

```verilog

class config_;
  rand bit [7:0]my_pts[$];
endclass: config_
 
class aac;
  config_ cfg; 
  bit[7:0] agt_pts[string][$] = '{"alu0":'{0:'h11}, "cpu0":'{0:'h11, 1:'h22}};
 
  function void perform_opr;
    cfg = new();
    assert(cfg.randomize with {
      cfg.my_pts.size() == agt_pts["cpu0"].size(); 
      //foreach(agt_pts["cpu0"][z])
      foreach(cfg.my_pts[z]) cfg.my_pts[z] == agt_pts["cpu0"][z];
    }) else $display("Randomization failed");
    
    foreach(cfg.my_pts[ii]) $display("my_pts[%0d] : %0h",ii,cfg.my_pts[ii]);
  endfunction: perform_opr
 endclass: aac
    
module assoc_array_cycling;
 aac aac_inst;
 initial begin
   aac_inst = new(); 
   aac_inst.perform_opr();
 end
endmodule: assoc_array_cycling

```

# Output:

ncsim\> run  
my\_pts[0] : 11  
my\_pts[1] : 22

---

_[View the full topic](https://verificationacademy.com/forums/t/expression-of-this-type-cannot-be-used-to-index-the-array/35426)._
