Understanding Reduction Operator sum() on Class Handles

Using Array reduction operator on Array of Handles gives the following error ::



typedef enum bit { OFF = 0  , ON = 1 } bulb ;

class Bulbs ;
 rand bulb bb ;
endclass

// In another class containing array of Handles :: rand Bulbs b[] 
constraint SUMM { b.sum() == 5 ; } 

Array reduction methods may only be applied on arrays of integral types if no ‘with’ expression is provided.
If a ‘with’ expression is present, the expression type must be integral .

So I tried the following which works ::


 b.sum() with ( int'( item.bb == ON ) ) == 5 ;

So I asked myself why does it work in this case ( Feel free to add more or correct me with [A/B/C] below )

[A] Since with() is used we can use sum() on Array of Handles

Integral types according to LRM 6.11.1 ::

The term integral is used throughout this standard to refer to the data types that can represent a single basic
integer data type, packed array, packed structure, packed union, enum variable, or time variable.

[B] So since item.bb refers to an enum type ( and ON is already enum ) the with expression is successful .

[C] The with() expression has integral types in it thereby qualifying it as an integral expression , am I right here ?

Regards ,
ABD

In reply to Have_A_Doubt:
[A] and [C] must both be true

[ B] It doesn’t matter what the type of bb is. The result of the == operator is a 1-bit integral type. That’s enough to avoid the compiler error, but not enough for the solver to succeed. You need to cast the result of the equality to enough bits to hold the sum without overflowing. (See http://go.mentor.com/verilog-in-constraints)

In reply to dave_59:
Thanks Dave ,

Isn’t it necessary for bb to be an integral type ? Had bb been another handle it wouldn’t work I believe

In reply to Have_A_Doubt:

No. if bb were a handle, you could have

b.sum() with ( int'( item.bb == null ) ) == null_count ;