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 #2529: explicit protection package #3651
Fix #2529: explicit protection package #3651
Conversation
Perhaps you could add a couple of failing tests. Like accessing a symbol which you don't have access to. Also pass some invalid stuff to the package keyword. |
Could you also create a pull request which updates the documentation. |
Added tests have failing one too, via
Any valid identifier is valid there right now and it is kind of intended. You may define protection for a package not yet encountered. I can't see any reason why it should be prohibited but I may have missed something. |
Updated linked grammar PR to include doc changes too. |
I thought it would be nice to check the error message as well. I don't know what others think.
Then add a test that doesn't use a valid identifier 😉, or something that is not an identifier at all. I don't know if I'm too cautious, but I don't think it hurts add. |
* Returns: | ||
* see description | ||
*/ | ||
bool Package::isSubpackage(Package* pkg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads funny as a binary relation.
x.isSubpackage(y);
I would read that as "is x a subpackage of y?" It took me a while to figure it out, and I only understood it by reading the document comment in the end. I would rename the function to something like isAncestorPacakgeOf
or similar.
That's literally the only thing wrong I found with this diff.
Will update according to all comments as soon as I will figure out what this DDOC test failure is about :) |
Also link to NG discussion : http://forum.dlang.org/post/cwjqwlkakjuwhfewvlhf@forum.dlang.org |
Why does the error message says: "attribute __anonymous"? |
Because this is how defailt formatting for attribute / dsymbol is defined. And I have no idea how it supposed to be changed (other than overriding all relevant methods) :( Need someone more experienced with dmd to chime in here. |
Ok, kind of of figured out that error message thing, does not look pretty but it works. All previous review comments should be addressed by now. |
|
status? |
|
This failure drives me crazy. @DmitryOlshansky maybe you have any ideas? Exception refers to |
Nailed it. Exception was referring not to source file but compiler output. Stupid invalid memory access mistake :) |
Looks like its passing on the build hosts it was failing on, glad I could be of help! |
Yay, green. |
@@ -283,14 +303,14 @@ class ScopeDsymbol : public Dsymbol | |||
|
|||
private: | |||
Dsymbols *imports; // imported Dsymbol's | |||
PROT *prots; // array of PROT, one for each import | |||
PROTKIND *prots; // array of PROTTYPE, one for each import |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/PROTTYPE/PROTKIND/
The overall direction looks fine to me. |
That should be all, waiting for an auto-tester. |
// protection to | ||
if ((pAttrs->protection.kind == PROTpackage) && (token.value == TOKlparen)) | ||
{ | ||
pkg_prot_idents = parseQualifiedIdentifier("protection package"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespace problem
Meta comment - renaming PROT to Prot made for a lot of extra diffs, making it harder to see what was actually changing. It also likely makes for frequent rebasing of this and other PR's. |
Thanks for comments!
Keeping old name will only hide the issue, most of conflicts come from the fact that Will update to latest master this weekend. |
Makes it possible to easily add additional protection information and differentiates between protected imports and actual attribute.
This commit adds capability of parsing and resolving explicit package defined for package protection attribute. Adjusting acess checks to use it will be done in separate commit.
Fix relevant issue by allowing to explicitly define package to bind protection attribute to. Defaults remain unchanged.
Using non-existent or non-parent package as an argument to 'package' protection attribute will result in compile-time error. Test cases with error message output added.
Now includes actual protection attribute kind and package name (if any) into error message. Also stores location information from the parser.
Rebased, addressed all but one @WalterBright comment (asked clarification for that one) |
Green |
Fix #2529: explicit protection package
Thanks! A most pleasant surprise :) |
[Refactoring] around protection code fixed in the PR #3651
Needs to go into the changelog. |
Assign me please |
Github wouldn't let, sorry @Dicebot, but I can ping you for a reminder. |
https://issues.dlang.org/show_bug.cgi?id=2529
This does not implement original proposal from linked bugzilla entry but addresses same goal.
Currently there is no way to use
package
protection attribute with deeply nested package hierarchy, forcing to either use flat one orpublic
protection. This is one of blocking issues for further usage ofpackage.d
in Phobos and one of reasons why namespace hacks are so popular.For example, if helpers in
std.internal
will be marked aspackage
, onlystd.internal
will be able to access those, but not rest ofstd
. This PR fixes it by allowingpackage(<pkgname>)
syntax to explicitly define owning package.This new syntax will work:
Exact semantics can are described by added "protection" tests to
test/compilable
(last commit in this PR).Plain
package
behavior is unchanged and thus no breaking changes introduced.