-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
errors with getSymbolsByUDA to get a private members #5344
errors with getSymbolsByUDA to get a private members #5344
Conversation
std/traits.d
Outdated
| @@ -7664,9 +7664,13 @@ template getSymbolsByUDA(alias symbol, alias attribute) { | |||
| .format(names[0])); | |||
| } | |||
|
|
|||
| // filtering not compiled members such as not accessible members | |||
| enum noNotCompiledMembers(string name) = (__traits(compiles, __traits(getMember, symbol, name))); | |||
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 name is wired.
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.
yes sorry I'm not very good with English, how about excludeInaccessibleMembers or noInaccessibleMembers?
|
found another problem - if put |
|
You must use |
|
Totally agree with you, If I want to add some useful attribute like |
|
I've deleted previous comments so there might be a misunderstanding. Actually the bug you try to fix is not a bug anymore. You must use __traits(getMember) as symbol and not the symbol directly. This has for effect to bypass the protection. |
|
I do not quite understand why this is not a bug - errors fall specifically in the struct {
@Field int testField = 10;
private int member = 0;
}When I try to call |
|
ping @bbasile |
|
My wish to make most of the built-in traits free from protection attribute interferes. Consider my previous comments as non-existent. |
|
Ok, @UplinkCoder all corrected, will there be more comments? |
std/traits.d
Outdated
| @@ -7664,12 +7664,20 @@ template getSymbolsByUDA(alias symbol, alias attribute) { | |||
| .format(names[0])); | |||
| } | |||
|
|
|||
| // filtering inaccessible members | |||
| enum noInaccessibleMembers(string name) = (__traits(compiles, __traits(getMember, symbol, name))); | |||
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.
double negation is wired.
isAccessible
also the () around the __traits-Expression are not needed.
std/traits.d
Outdated
| // filtering out nested class context | ||
| enum noThisMember(string name) = (name != "this"); | ||
| alias membersWithoutNestedCC = Filter!(noThisMember, __traits(allMembers, symbol)); | ||
| alias membersWithoutNestedCC = Filter!(noThisMember, withoutInaccessibleMembers); |
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.
membersWithoutNestedCC ?
What does this stand for ?
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.
@UplinkCoder this one was here before, but now it's redundant, fixed it.
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.
@UplinkCoder fixed
std/traits.d
Outdated
| // filtering out nested class context | ||
| enum noThisMember(string name) = (name != "this"); | ||
| alias membersWithoutNestedCC = Filter!(noThisMember, __traits(allMembers, symbol)); | ||
| alias membersWithoutNestedCC = Filter!(noThisMember, withoutInaccessibleMembers); |
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.
@UplinkCoder this one was here before, but now it's redundant, fixed it.
std/traits.d
Outdated
| static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[0], Attr)); | ||
| static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[1], Attr)); | ||
|
|
||
| struct A |
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 could go in a unittest-block,
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.
LGTM
std/traits.d
Outdated
| alias membersWithoutNestedCC = Filter!(noThisMember, __traits(allMembers, symbol)); | ||
| // filtering inaccessible members | ||
| enum isAccessibleMember(string name) = __traits(compiles, __traits(getMember, symbol, name)); | ||
| alias withoutInaccessibleMembers = Filter!(isAccessibleMember, __traits(allMembers, symbol)); |
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.
again please no double negation.
accessibleMembers
std/traits.d
Outdated
| enum hasSpecificUDA(string name) = mixin("hasUDA!(symbol." ~ name ~ ", attribute)"); | ||
| enum isCorrectMember(string name) = __traits(compiles, hasSpecificUDA!(name)); | ||
|
|
||
| alias withoutIncorrectMembers = Filter!(isCorrectMember, withoutInaccessibleMembers); |
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.
correctMembers
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.
please address the comments
|
@UplinkCoder corrected, but for some reason |
|
@sysint64 rebase on ~master. |
0a25eb4 to
c233122
Compare
|
@UplinkCoder it hasn't helped, |
|
@sysint64 squash please. |
|
@UplinkCoder sorry for the stupid question: what does the "squash please" mean? |
|
Squashing refers to merging the individual commits into one. |
That instead of merging 6 commits, we prefer to merge only one to keep the history nice and clean.
@UplinkCoder: Do you know this page: https://wiki.dlang.org/Guidelines_for_maintainers |
|
@sysint64 there seems to be a problem when building ggplot |
|
@UplinkCoder how can I reproduce it? |
Clone ggplotd and pass your locally build DMD to DUB with |
|
@UplinkCoder, @wilzbach I checked command: dmd.conf: |
|
Jenkins falls when he tries to compile with flag |
|
@UplinkCoder, @wilzbach I checked |
Quite likely, unfortunately I don't have access to restart jobs at Jenkins. I will try to restart manually by force-pushing the same changeset. |
c233122 to
cf668ab
Compare
|
@wilzbach, @UplinkCoder all checks have been passing, but for some reason doesn't run the |
|
This pull request may have introduced a regression: Your PR description says:
However, as per the above issue, it also affects symbols within the same module. |
there is test on this case which successfully passed: @safe unittest
{
enum Attr;
struct A
{
alias int INT;
alias void function(INT) SomeFunction;
@Attr int a;
int b;
@Attr private int c;
private int d;
}
// Here everything is fine, we have access to private member c
static assert(getSymbolsByUDA!(A, Attr).length == 2);
static assert(hasUDA!(getSymbolsByUDA!(A, Attr)[0], Attr));
static assert(hasUDA!(getSymbolsByUDA!(A, Attr)[1], Attr));
}You can't access to symbol only if this accessing leads to compilation error |
|
@sysint64 I think that test passes only because it's located inside the std.traits module. Suffice to say, it's not useful that we can access private members of types declared in std.traits specifically. |
|
@CyberShadow you are right it's not compiled, I suppose it's because all computations are produced inside the function in std.traits, old version of this function also in the future will stop working due to deprecation such access. |
|
@CyberShadow on current version of D not only does this method not work with private members also do not work |
Resolve #15335 Remove ability in getSymbolsByUDA to get a private members If it is located in another module.
If you trying to get symbols from another module you will get errors. This commit resolve this. Now you can access to all attributes if you have access otherwise you will not get private members but also not throws errors.
examples:
uda.d
main.d
In my program I do not get deprecation warning instead of this I get a bunch of errors.
With this patch all works fine.