Consider the following: --- module bugtrait; class A { private this() {} private void foo() {} } --- module bugtrait2; import bugtrait; void main() { pragma(msg, __traits(getVisibility, __traits(getMember, A, "foo"))); pragma(msg, __traits(getVisibility, __traits(getMember, A, "this"))); } --- private Error: no property `this` for type `bugtrait.A` The "foo" works fine, it bypasses private when getting the member, allowing me to inspect its visibility, deprecation status, etc. But then for "this", it fails, even though traits(allMembers) returns it, causing an annoying special case.
```d pragma(msg, __traits(getVisibility, __traits(getMember, A, "__ctor"))); ```
__ctor is not returned by allMembers and is not supposed to be used anyway, since the double leading underscore is a reserved detail to the compiler implementation.
It also doesn't work if the constructor is auto-generated instead of explicitly put in anyway.
The bug is not about visibility, but trying to use `this` to access the ctor. If you make `this` public, you'll still get the same error message. > __ctor is not returned by allMembers It is. https://dlang.org/spec/traits.html#allMembers We use it directly because there's no alternative. > But then for "this", it fails, even though traits(allMembers) returns it, causing an annoying special case. When I add: > pragma(msg, __traits(allMembers, A)); After the other, I get: > tuple("__ctor", "foo", "toString", "toHash", "opCmp", "opEquals", "Monitor", "factory") How do you get the `"this"` ?