Open pataei opened 1 year ago
added to the casting issue on P4 spec repo.
Neither P4 spec nor Petr4 checks for enum fields to be distinct but I'd imagine a well-formed enum type must have distinct fields.
I think petr4 rejects enum field dups. E.g. running petr4 typecheck
on this program
enum A {
X,
X
}
fails with a "constant already defined!" error about A.X
. But if it's missing from the definition of type well-formedness we should probably add it to that.
Ahh! Then it must be checked where the constants are inserted.
Checked and in fact, it was in insert_const
helper function. Thanks Ryan!
Petr4 code
let expr_typed = cast_expression env expr_ctx underlying_type expr in
allows the implicit cast of initializers.P4 spec (v1.2.3)
Fixes
Side note on serializable enums
Note that Petr4 checks that the fixed-width integers have constant size by translating the underlying type from types.type.t to typed.type.t.