Accessing enum type of data

In reply to kolopipo:

OK, you are asking if the above code is legal(after fixing typos). My answer is unfortunately, yes.

An enum variable is an integrally packed type, and you can always select a bit or range of a packet type variable. And the type of a select of a packed type is always a simple integral type, even if you select the entire enumerated value. In your example, you are selecting a bit of a enum variable with a constant that just happens to be an enum label of the same variable. The code is interpreted as

fruits[32'd0] = 1'b1;
fruits[32'd2] = 1'b0;

At the end of your initial block, fruits will have the value banana.

So the following is legal syntax, even though it puts an out-of-range value into an enum variable without a cast, and that is very unfortunately legal.

fruits[31:0] = 6; // legal
fruits = 6; // illegal without a cast