Facing error when passing arguments in the hierarchy when using $assertoff

I am trying to exercise the below code but it throws the below error.

function disable_assert(int clk_out, int logic_gen);

$assertoff(0,hdl_top.i_clock_gen.gen_clock_out**[clk_out].clock_mux_u.logic_gen[logic_gen]**.i_sync_en.check_level_high_duration);

endfunction

Error found while trying to resolve cross-module reference. token ‘clk_out’ ‘logic_gen’. Originating interface ‘clock_gen_intf’, first module hit ‘hdl_top’.

The same code if I use like below it works.

$assertoff(0,hdl_top.i_clock_gen.gen_clock_out**[0].clock_mux_u.logic_gen[0].i_sync_en.check_level_high_duration); $assertoff(0,hdl_top.i_clock_gen.gen_clock_out[0].clock_mux_u.logic_gen[1]**.i_sync_en.check_level_high_duration); $assertoff(0,hdl_top.i_clock_gen.gen_clock_out[0].clock_mux_u.logic_gen[2].i_sync_en.check_level_high_duration);

$assertoff(0,hdl_top.i_clock_gen.gen_clock_out[1].clock_mux_u.logic_gen[0].i_sync_en.check_level_high_duration); $assertoff(0,hdl_top.i_clock_gen.gen_clock_out[1].clock_mux_u.logic_gen[1].i_sync_en.check_level_high_duration); $assertoff(0,hdl_top.i_clock_gen.gen_clock_out[1].clock_mux_u.logic_gen[2].i_sync_en.check_level_high_duration);

Can someone tell me where it is going wrong.

In reply to Dhanusuya:

I’m assuming gen_clock_out and logic_gen are begin/end names of generated blocks. You cannot use variables as indexes like an array. A constant numeric literal works as you discovered, as well as using another generate-for loop

for(genvar x = 0;x<2;x++)
  for(genvar y = 0;y<3;y++)
   initial $assertoff(0,hdl_top.i_clock_gen.gen_clock_out[x].clock_mux_u.logic_gen[y].i_sync_en.check_level_high_duration);

There are other tricks you could use depending on your situation.