p4lang / p4-spec

Apache License 2.0
178 stars 80 forks source link

Misleading code example for 8.24. Operations on types that are type variables #1295

Open jaehyun1ee opened 3 months ago

jaehyun1ee commented 3 months ago

Below is the code example from spec section 8.24 explaining the operations on types that are type variables. A local variable x of type T is defined inside the apply block of a control declaration.

control C<T>() {
    apply {
        T x;  // the type of x is T, a type variable
    }
}

However, section 14 on control block mentions that,

Unlike control type declarations, control declarations may not be generic

So the above example is an invalid P4 program where C is a generic control declaration (not a control type declaration). I believe below example would be more appropriate for the purpose.

void f<T>() {
   T x; // the type of x is T, a type variable
}
vlstill commented 2 months ago

I agree the example is invalid and the sentence above it should not mention controls and parsers. Can you please open PR with the change?