traits getProtection

Robert Jacques sandford at jhu.edu
Tue Apr 3 06:13:59 PDT 2012


On Mon, 02 Apr 2012 08:05:09 -0500, Dmitry Olshansky <dmitry.olsh at gmail.com> wrote:

> On 02.04.2012 16:04, Adam D. Ruppe wrote:
>> On Monday, 2 April 2012 at 09:26:07 UTC, Dmitry Olshansky wrote:
>>> It's all nice and well, but I believe part of the reason of say
>>> private protection is that user is never ever able to see(!) it. Thus
>>> it user can't depend on private members being there, which is a good
>>> thing.
>>
>> That's not the way it is right now in D: if you use the
>> reflection traits, you can see and access private members.
>>
>> Worse yet, the way it is now, there's no way to tell
>> they are marked private when using reflection!
>>
>
> Awful.

As someone who has implemented a runtime reflection library in D, it is entirely possible to detect whether a function is marked private/protected or not using __traits today. In fact, IIRC, there is no way to break protection using __traits; what the op is referring to is .tupleof, which can be used to break protections of fields if you have the full source code.


More information about the Digitalmars-d mailing list