Constraint solver failed when accessing a null array

In reply to prashant.kaushik:

Hi,

Thanks, I tried your suggestion as below, but it results in my original error which was a “Constraint null error array”

class cmd_item extends uvm_sequence_item;

    // UVM automation macro
    `uvm_object_utils(cmd_item)

    rand byte unsigned sgl[][][16];

    constraint C_NUM_ELEMENTS {sgl.size inside { [5:5] }; }

    constraint C_NUM_DESCRIPTORS_PER_ELEMENT {
        foreach (sgl[i,,]) {
            sgl[i].size inside { [5:10] };
        }
    }

    constraint C_SET_LENGTH_FIELD {
        foreach (sgl[i,j,]) {
            (i <= sgl.size-2) -> (sgl[i][j][8] == sgl[i+1].size);
            (i == sgl.size-1) -> (sgl[i][j][8] == 5); // This is application only for last element.
        }
    }

    function string sprint();
        string s;
        s = {s, $psprintf("\n[There are this many elements := %0d]\n", sgl.size())};
        foreach (sgl[i,])
            s = {s, $psprintf("[Segement %0d has this many descriptors := %0d]\n", i, sgl[i].size)};
        foreach (sgl[i,j])
            s = {s, $psprintf("[Segment := %0d, Descriptor := %0d, Length := %0d]\n", i,j, sgl[i][j][8])};
        return s;
    endfunction

endclass

module top;
  cmd_item c=new();
   initial repeat(1) begin
      assert(c.randomize());
      uvm_report_info("cmd_item", c.sprint());
   end
endmodule

Error-[CNST-NAE] Constraint null array error
…/tb/for_va_question.sv, 61
The constraint solver failed when accessing a null array
sgl__vcs_type[5].idx.
Please make sure array sgl__vcs_type[5].idx is allocated properly.

“…/tb/for_va_question.sv”, 61: top.unnamed$$_1: started at 0ps failed at 0ps
Offending ‘c.randomize()’
UVM_INFO @ 0: reporter [cmd_item]
[There are this many elements := 5]
[Segement 0 has this many descriptors := 5]
[Segement 1 has this many descriptors := 9]
[Segement 2 has this many descriptors := 10]
[Segement 3 has this many descriptors := 8]
[Segement 4 has this many descriptors := 10]