Duplicate match_kind declarations are allowed when they shoudn't
The spec mentions in 7.1.3. The match kind type that,
The match_kind type is very similar to the error type and is used to declare a set of distinct names that may be used in a table's key property (described in Section 14.2.1). All identifiers are inserted into the top-level namespace. It is an error to declare the same match_kind identifier multiple times.
However, p4c fails to reject a case when there is duplicate match_kind, for example,
match_kind { foo, bar }
match_kind { foo }
A related test case exists as pipe.p4 in testdata/p4_16_samples.
#include <core.p4>
match_kind {
ternary,
exact
} // core.p4 already defines those two
Also, this is in contrast with how the p4c frontend handles duplicate error declarations. p4c rejects duplicate error declarations. For example, below program is rejected.
error { FOO, BAR }
error { FOO }
// dup-error.p4(2): [--Werror=duplicate] error: FOO: Duplicates declaration FOO
Both error and match_kind declarations should only appear in target arch includes, never in user programs, so these rules should really just be codifying what actual arhcitectures (try to) do.
Yes, but I believe it would be a good practice to have a dup-check for match_kinds as the frontend already does with error types, for the sake of checking the validity of arch files.
Yes, but I believe it would be a good practice to have a dup-check for match_kinds as the frontend already does with error types, for the sake of checking the validity of arch files.
I agree, the check should not be omitted just because architecture programmers are considered "more trusted".