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

Fix Issue 18951 - package static method masked by public static method in class #8338

Merged
merged 1 commit into from Jun 8, 2018

Conversation

FeepingCreature
Copy link
Contributor

When selecting the "most-visible" overload method to check access,
treat package methods as public if they're visible; otherwise, private.
This avoids package methods that are perfectly visible being passed over
in favor of public (numerically more visible) overloads appearing later
in the class.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jun 6, 2018

Thanks for your pull request and interest in making D better, @FeepingCreature! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
18951 normal package static method masked by public static method in class

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#8338"

@FeepingCreature
Copy link
Contributor Author

Ping @RazvanN7 , @JinShil

@@ -543,7 +543,7 @@ extern (C++) bool checkSymbolAccess(Scope *sc, Dsymbol s)
* but doesn't recurse nor resolve aliases because protection/visibility is an
* attribute of the alias not the aliasee.
*/
public Dsymbol mostVisibleOverload(Dsymbol s)
public Dsymbol mostVisibleOverload(Dsymbol s, Module mod = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can get rid of the optional parameter and obtain the module form s by calling s.getModule [1]

[1] https://github.com/dlang/dmd/blob/master/src/dmd/dsymbol.d#L327

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No? The module is the module the symbol is supposed to be visible from.

@JinShil JinShil changed the title Fix Issue 18951. Fix Issue 18951 - package static method masked by public static method in class Jun 6, 2018
src/dmd/access.d Outdated
* except package() is "private" if the module is outside the package;
* otherwise, "public".
*/
Prot effectiveProtAt(Dsymbol d, Module mod)
Copy link
Contributor

@JinShil JinShil Jun 6, 2018

Choose a reason for hiding this comment

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

Please spell this out as "effectiveProtection". I had to read the comment to understand what "Prot" meant.

Ok, I'll take that comment back. It appears prot is the current convention...unfortunately. But it would probably benefit from "From" rather than "At". Even the comment uses "from".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Protection from Module" sounds like a D&D spell. 😄

src/dmd/access.d Outdated
* except package() is "private" if the module is outside the package;
* otherwise, "public".
*/
Prot effectiveProtAt(Dsymbol d, Module mod)
Copy link
Contributor

Choose a reason for hiding this comment

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

I also recommend making this a nested function in the mostVisibleOverload function, or at a minimum, make it private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, and renamed to protectionInModule

@FeepingCreature FeepingCreature force-pushed the fix/Issue_18951 branch 3 times, most recently from 652c322 to 9afabdb Compare June 6, 2018 14:15
src/dmd/access.d Outdated
* except package() is "private" if the module is outside the package;
* otherwise, "public".
*/
Prot protectionInModule(Dsymbol d, Module mod = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this function can be static.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still prefer "From" over "In".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed?

When selecting the "most-visible" overload method to check access,
treat package methods as public if they're visible; otherwise, private.
This avoids package methods that are perfectly visible being passed over
in favor of public (numerically more visible) overloads appearing later
in the class.
@FeepingCreature
Copy link
Contributor Author

ping? Fail is almost certainly unrelated.

@JinShil
Copy link
Contributor

JinShil commented Jun 8, 2018

I deprecated that test. It should retest in about 30 minutes or so.

@FeepingCreature
Copy link
Contributor Author

yup, works. do we need another reviewer?

@dlang-bot dlang-bot merged commit 5f3b12b into dlang:master Jun 8, 2018
@FeepingCreature
Copy link
Contributor Author

Woo!

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