Open
Description
The built-in method isValid
should not take any argument or type argument. This check works in P4C, e.g.,
extern void sink(in bool b);
header Hdr { bit<32> x; }
control C(in Hdr hdr);
package P(C c);
control CImpl(in Hdr hdr) {
apply { sink(hdr.isValid(1w1)); }
}
P(CImpl()) main;
fails as expected:
3-is-valid-rep-well.p4(9): [--Werror=type-error] error: 'hdr.isValid(1w1)'
apply { sink(hdr.isValid(1w1)); }
^^^^^^^^^^^^^^^^
---- Actual error:
isValid: 1 arguments supplied while 0 are expected
---- Originating from:
3-is-valid-rep-well.p4(9): Function type 'isValid' does not match invocation type '<Method call>'
apply { sink(hdr.isValid(1w1)); }
^^^^^^^^^^^^^^^^
However, when isValid
is called on a constant value, seems like type inference or constant folding pass accepts isValid
call with arguments or type arguments as valid.
header h {}
bool f() {
return ((h) { }).isValid(_);
}
control C();
package P(C c);
control CImpl() { apply { f(); } }
P(CImpl()) main;
The above program is accepted by p4test
. Running with --top4
to inspect each pass, at -0017-FrontEnd_12_TypeInference.p4
, the function f
becomes:
bool f() {
return true;
}