[Issue 15335] getSymbolsByUDA fails if type has private members

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Nov 16 09:43:25 PST 2015


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

bb.temp at gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bb.temp at gmx.com

--- Comment #1 from bb.temp at gmx.com ---
I've encountered a similar issue yesterday. It looks like the only way to solve
this is to make `getSymbolsByUDA` a mixin template containing the current
function. Then when the template is mixed in the local scope, there's no more
fake warning in case when a private member is accessed (even in "friends"
classes or struct, so inside the same module.

For example in my case I finished with this:

---
mixin template ScopedReachability()
{
    bool isMemberReachable(T, string member)()
    if (is(T==class) || is(T==struct))
    {
        return __traits(compiles, __traits(getMember, T, member));
    }
}
---

If I mix ScopedReachability where `isMemberReachable` has to be used it works.
Previously, calling the function template was leading to the same error message
that's reported here...



...So, back to real topic, by analogy:

---
mixin template ScopedgetSymbolsByUDA
{
    template getSymbolsByUDA(alias symbol, alias attribute)
    {
        import std.typetuple : Filter, staticMap, TypeTuple;

        static enum hasSpecificUDA(alias S) = hasUDA!(S, attribute);
        alias StringToSymbol(alias Name) = Identity!(__traits(getMember,
symbol,       Name));
        alias getSymbolsByUDA = Filter!(hasSpecificUDA, TypeTuple!(symbol,
        staticMap!(StringToSymbol, __traits(allMembers, symbol))));
    } 
}
---

should work. Instead of calling the template, you first mix
`ScopedgetSymbolsByUDA` and then you call the `getSymbolsByUDA` that's local.
Of course this is not a workaround that I propose here. I think this should be
done like this in phobos.

--


More information about the Digitalmars-d-bugs mailing list