Specify that serializable_enum[hi:lo] is a valid L-value expression
At 2021-Dec-06 LDWG meeting during discussion of PR https://github.com/p4lang/p4-spec/pull/982, it was noticed that adding an explicit cast to an expression like serializable_enum[3:0] to ((bit<W>) serializable_enum)[3:0] where bit<W> is the underlying type of the type of the serializable enum is not a valid L-value expression, so it seemed best if the spec did not define such an L-value as a case where an implicit cast could be added, at least not if the meaning of an implicit cast was the same as adding an explicit cast in the source code.
An alternate approach discussed then was to make a special case for expressions like serializable_enum[3:0] when used as L-values, I believe somehow defining such an expression as one that could be assigned a value of type bit<4> (or something that can be implicitly cast to bit<4>).
I may have misinterpreted the desired approach here, but wanted to create an issue that should remind others of the issue, and they can clarify in follow-up comments if this original description is incorrect.
I think first we should answer whether serializable_enum[3:0] should be an l-value.
If it should, then we should add description of slicing in 8.3. Operations on enum types, just like operations for bit<> and int<>.
Also, we may want to clarify the wording a bit to say "slices of l-values are also l-values" in section 8.5-8.7.
This should be resolved if we have the concept of numeric types. https://github.com/p4lang/p4-spec/pull/1008
2022-Mar-07 LDWG meeting notes:
- One proposed change would be to add to section 8.3 to add slice operations explicitly.
- Clarify that slices of L-values are also L-values, and the type of that L-values should be
bit<W>, regardless of whether the underlying type of the serializable enum isbit<W>orint<W>. - See Qinshi's previous comment, which may help 'factor' spec language better here.