Valid expression types in the with clause

I was trying a variation of sum() using different with() clause ( edalink )

constraint Even_Index_Sum { a.sum() with((item.index[0] == 0) ?item:0) == 20; }
      

constraint Sum_wo_Msb { b.sum() with ( int'(item[($bits(item)-2):0] ) ) == 30; }

When tested across the major 3 tools I observe one tool throws compilation error , 2nd tool accepts it whereas 3rd tool hasn’t implemented it yet

[Q1] Does LRM restrict using bit-select of an index / element within with() clause ?

[Q2] As per LRM what would be an illegal expression type in with() clause ?ith() clause ?

Thanks

The issue here is that, syntactically, the index is defined as a method of the iterator, not as a variable that can have bits selected. It should be a compiler error. The correct way to do this in SystemVerilog is to take a bit-select of a concatenation.

    constraint Even_Index_Sum { a.sum() with ( ({item.index}[0] == 0 ) ? item : 0 ) == 20; }

Thanks Dave

On revisiting the compilation error I see that constraint Sum_wo_Msb is legal

I am not clear on the reason behind using a concatenation operator and why is the expression considered legal with it

Section 7.12.4 of LRM says

Return type of the index method is an int for all array iterator items except associative arrays

Does {item.index} treat the int type result as a variable / packed array element ?

Regarding [Q2] would it be correct to state that when resultant expression within the with() clause is non-integral or string type, it’s considered illegal

There’s a slight complication here because the 1800-2023 LRM introduced an enhancement along with (02735: Ballot Comment #48: Chaining of method calls - Accellera Mantis) that allows selecting bits [] of a function call. The LRM now supports bit/part selects of variables, concatenations, and the return value of a method call. Therefore, both item.index[0] and {item.index}[0] are valid and equivalent. However, it seems that tools have varying levels of support for either form.

You can use any valid types for the operator being used in the reduction. For instance, the sum() and product() operators can accept both real and integral types within the with() clause. On the other hand, the and(), or(), and xor() operators can only accept integral types.

Using bit-select of concatenation I observe that one tool throws the following Compilation Error

Error-[SCONCNA] Selection of concatenation not allowedtestbench.sv, 15tb, 
"{item.index}[0]"  
A selection of a concatenation is not allowed in constraint.

Whereas using bit-select directly on the iterator method throws Compilation Error saying ::

Bit or part select on function call is not yet implemented in constraints.

A verbose solution which works across all tools

constraint Even_Index_Sum { a.sum() with ( ((item.index % 2) == 0) ? item : 0 ) == 20; }

Personally, I was trying to avoid using modulus operator.

Unfortunately, the other alternatives don’t work across all tools (despite the fact that they are legal as per LRM)