In reply to peter:
Section 7.12 Array manipulation methods defines all methods (which includes sum()) to accept an optional iterator_argument variable name. If you do not declare one, its default name becomes item. The LRM has the following example
logic [7:0] m [2][2] = '{ '{5, 10}, '{15, 20} };
int y;
y = m.sum with (item.sum with (item)); // y becomes 50 => 5+10+15+20
The first
item variable is iterating of the first dimension of the array, and the second item a nested iteration of the second dimension. The example could also be written with explicitly declared iterator names
y = m.sum(item1) with (item1.sum(item2) with (item2)); // y becomes 50 => 5+10+15+20
The above has the benefit of not hiding the first iterator variable from the second nested iteration. Useful in more complex constraint equations.
All SystemVerilog simulators on EDAPlayground produce an error for this code
module top;
logic[7:0] m[3][2] = '{'{1,2},'{3,4},'{9,8}};
initial $display(m.sum with(item > 4 ? 1 : 0));
endmodule
The error is because
item is this code iterates 3 times as a 1-dimensional array with a size of 2. You cannot use a relational operator > on an array.