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 15371 - __traits(getMember) should bypass the protection #9585

Merged
merged 1 commit into from
Apr 12, 2019

Conversation

RazvanN7
Copy link
Contributor

No description provided.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @RazvanN7! 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
15371 enhancement __traits(getMember) should bypass the protection

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#9585"

@adamdruppe
Copy link
Contributor

interesting this would make things easier to use

Scope* scx = sc.push();
scx.flags |= SCOPE.ignoresymbolvisibility;
scx.flags |= SCOPE.ignoresymbolvisibility | SCOPE.noaccesscheck;
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn’t this apply to more traits than those mentioned above?

Copy link
Contributor Author

@RazvanN7 RazvanN7 Apr 10, 2019

Choose a reason for hiding this comment

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

Yes, but it does not affect them; more specifically: from a total of 5 affected traits we have hasMember, that was already working and SCOPE.noaccesscheck does not affect it and getVirtualMethod/Functions for which it does not apply, because private members are never virtual. The other 2 are specified.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about protected, did that already work.

@RazvanN7
Copy link
Contributor Author

Ok, this causes phobos to break; silent change of code behavior. Ideas? I don't see other way then to deprecate this trait and implement a new one :-S

@adamdruppe
Copy link
Contributor

adamdruppe commented Apr 10, 2019 via email

@RazvanN7
Copy link
Contributor Author

@adamdruppe yeah, I think that commenting it and then fixing it after this is merged is the way to go

$(LI getOverloads)
)

This fixes a long-standing issue in D where the allMembers trait would correctly return non-public members but those non-public members would be inaccessible to other traits.
Copy link

Choose a reason for hiding this comment

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

The problem I and other encountered is also tied to the fact that a library trait located in one module could not work at a at the use site because it was instantiated elsewhere. The same library trait, copied (or mixed in) at the use site worked just fine.

Copy link

Choose a reason for hiding this comment

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

I forgot to say but somewhere it should be documented that from now it's a good practice to check the protection and to apply it unless "you know what you do".

@thewilsonator
Copy link
Contributor

This GTG?

void main()
{
A a;
static assert(__traits(compiles, __traits(hasMember, A, "a")));
Copy link
Member

Choose a reason for hiding this comment

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

Why is this wrapped in a __traits(compiles? We can drop that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I simply copy pasted the test. Yes we can, done.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! __traits(compiles is a bit of an anti-pattern in compilation as you don't get the real error message if you change/break DMD and the test fails.

@RazvanN7
Copy link
Contributor Author

This GTG?

As far as I am concerned, yes.

@dlang-bot dlang-bot merged commit 7b64f1f into dlang:master Apr 12, 2019
@adamdruppe
Copy link
Contributor

adamdruppe commented Apr 12, 2019 via email

@MartinNowak
Copy link
Member

I should mention that we should remove the old access mechanism altogether.

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

Successfully merging this pull request may close these issues.

7 participants