Are structure-valued expressions subject to implicit casts?
In the new section on structure-valued expressions, the spec says "The typeRef can be omitted if it can be inferred from context, e.g., when initializing a variable with a struct type." Is this an implicit cast or is it a separate kind of inference? If it's an implicit cast, it should be included in the section 8.9.2 on implicit casts.
I could say that the answer is "it depends". The syntax of struct expressions is designed to look like a cast, but internally the compiler treats it differently. I guess we could say that the compiler implicitly casts list expressions to struct expressions when used in a context that requires it.
I think it is at least important to recognize if assigning list/structure-valued expressions to tuples/structs/headers are applying implicit casts to its fields recursively in the spec. This example from the spec requires implicit casts.
struct S {
bit<32> a;
bit<32> b;
}
S s;
// Compare s with a structure-valued expression
bool b = s == (S) { a = 1, b = 2 };
It is important to recognize that implicit casts are added when needed, but not explicit casts. For example
bool b = s == (S) { a = 8w1, b = 8w2 };
is invalid and rejected by the BMV2 compiler.
In the interest of tidying up the set of active issues on the P4 specification repository, I'm marking this as "stalled" and closing it. Of course, we can always re-open it in the future if there is interest in resurrecting it.