www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15371] New: __traits(getMember) should bypass the protection

https://issues.dlang.org/show_bug.cgi?id=15371

          Issue ID: 15371
           Summary: __traits(getMember) should bypass the protection
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bb.temp gmx.com

"__traits(getMember,...)" should always work, whatever is the member protection
(as long as the symbol is a valid one).

The current limitation is problematic because it prevents to write functions
related to traits in a separate dedicated modules (e.g mylib.traits)

Every time a "__traits(getMember,...)" has to be used the only solution to make
it works with a private member is to write again and again the code (or to warp
the function in a mixin template).

Since there is also the traits verb "getProtection", it still would be possible
to respect the protection or not.

In case this wouldn't be clear, more concretly:

======================================
module mylib.traits;

mixin template ScopedReachability()
{
    bool isMemberReachableGood(T, string member)()
    if (is(T==class) || is(T==struct))
    {
        return __traits(compiles, __traits(getMember, T, member));
    }
}
Nov 21 2015