allMembers and getMember traits behavior

Artur Skawina art.08.09 at gmail.com
Fri Jun 21 07:48:19 PDT 2013


On 06/21/13 15:50, Martin wrote:
> On Friday, 21 June 2013 at 13:42:44 UTC, Artur Skawina wrote:
>>>    pragma(msg, __traits(getProtection, mixin("TestClass." ~ member)));
> Thanks, that sort of works. It prints "private" but then immediately gives an error:
> test.d(12): Error: class main.TestClass member value is not accessible
> 
> Sigh, this is DMD 2.063.2 by the way.

Sorry, didn't test that one, just used the right symbol; it has the same
problem as your original issue. Clearly, the getProtection trait wasn't
designed with inaccesible symbols in mind. And no, 'getMember' bypassing
the protection would not be a good idea (would make it too easy to mistakenly
access private data in generic code). getProtection should probably just
take two args, just like getMember, which would allow it to safely ignore
the normal access rules.

Right now, you can use 'tupleof', which bypasses the visibility attrs:

   alias T = TestClass;
   foreach (I, TYPE; typeof(T.tupleof)) {
        pragma(msg, __traits(getProtection, T.tupleof[I]), " ",
                    TYPE, " ",
                    __traits(identifier, T.tupleof[I]), ";");
   }

artur


More information about the Digitalmars-d mailing list