p4c
p4c copied to clipboard
overeager typechecking of generic types.
Consider the following program with a generic function (minor change of testdata/p4_16_samples/function.p4):
T max<T>(in T left, in T right) {
if (left > right)
return left;
return right;
}
control c(out bit<16> b) {
apply {
b = max(16w10, 16w12);
}
}
control ctr(out bit<16> b);
package top(ctr _c);
top(c()) main;
It fails with error message
function2.p4(2): [--Werror=type-error] error: left > right: not defined on T and T
if (left > right)
^^^^^^^^^^^^
However, it would seem to be ok, as the max
function is only ever instantiated with bit<16>
for T
, which should be ok. If you replace the explicitly typed constants as max(10, 12)
, you get even more errors, even though that should be ok too.