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

Fixed bug in name resolution; better shadowing tests #349

Merged
merged 1 commit into from
Mar 7, 2017

Conversation

mihaibudiu
Copy link
Contributor

Also, make sure that type parameters, apply parameters and constructor parameters have distinct names.

addToContext(c->type->typeParameters);
addToContext(c->type->applyParams);
addToContext(c->constructorParams);
addToContext(c); // add the locals
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jnfoster: This change ensures that parameters enter the scope before the locals.

@@ -180,6 +180,7 @@ ResolveReferences::ResolveReferences(ReferenceMap* refMap,
void ResolveReferences::addToContext(const IR::INamespace* ns) {
LOG1("Adding to context " << dbp(ns));
BUG_CHECK(context != nullptr, "No resolution context; did not start at P4Program?");
checkShadowing(ns);
context->push(ns);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this will now check every case of shadowing. Are there cases where shadowing should not be a warning? Actions in a control with the same name as some non-action global thing? Cases where a programmer might reasonably expect to reuse a name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All I can tell you is that there are no new warnings on the public tests we have.
If this is too strict we can refine it later.

@ChrisDodd ChrisDodd merged commit 98276ad into p4lang:master Mar 7, 2017
continue;
}
if (pnode->is<IR::Type_Method>() && node->is<IR::Type_Method>())
// Methods can overload each other if they have a different number of arguments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbudiu-vmw You deleted the check that they have different numbers of parameters. Does this code now allow any pair of methods with the same name to shadow each other?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will just avoid giving a shadowing warnings for all methods.
There is another check somewhere that two methods may not have the same signature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

Do you happen to know where that is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One case is in Type_Extern::lookupMethod.
I don't remember if there is another one.
This will signal an error only if the method is invoked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants