Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is shadowing of functions in the same namespace intended? #5096

Open
jaehyun1ee opened this issue Jan 12, 2025 · 0 comments
Open

Is shadowing of functions in the same namespace intended? #5096

jaehyun1ee opened this issue Jan 12, 2025 · 0 comments
Labels
p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).

Comments

@jaehyun1ee
Copy link

As far as I understand about p4c, p4c generally disallows variable and function shadowing within the same namespace as in the spirit of C/C++. (i.e., it disallows duplicate declarations)

However, issue3699.p4 is accepted by the p4c frontend as valid.

void f1(in h[(max |+| max) == max ? 1 : -1] a){}
void f1(in h[(max |+| 0) == max ? 1 : -1] a){}
void f1(in h[value1 == max ? 1 : -1] a){}

It is a bit odd because, first, function f1 is not overloaded. The three declarations have identical parameter arity and parameter names, so they are identical function declarations modulo overloading.

Second, while this is allowed, duplicate declaration of variables or actions are disallowed by p4c. e.g.,

const bit<32> c = 1;
const bit<32> c = 1; // rejected
action a() {}
action a() {} // rejected

Is this behavior, of allowing duplicate declaration of functions intended in p4c?

@fruffy fruffy added the p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).
Projects
None yet
Development

No branches or pull requests

2 participants