2D array constraint randomization

In reply to dave_59:
I run the code below, but failed with meaasge “Identifier ‘D1’ has not been declared yet”, Why is it possible in the tb_top but not in the constraints c1?


class A;
  rand bit [4:0] a [3][3];
  constraint c1 {
  //      a.sum() with (item.sum()) == 15;
    a.sum(D1) with (D1.sum(D2) with (32'(D2))) == 9;
  }
endclass
 
module tb_top;
  A h = new;
  initial begin
    repeat(10) begin
    assert (h.randomize);
    $display("a = %p", h.a);
    //$display(h.a.sum(D1) with (D1.sum(D2) with (32'(D2))));
    end
  end
endmodule