www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15874] New: getSymbolsByUDA fails if struct has no UDAs

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

          Issue ID: 15874
           Summary: getSymbolsByUDA fails if struct has no UDAs
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: uldis.kalninsh gmail.com

I think, this specific case should work, but it does not. 

struct Test {
    int x;
}

struct UDA {
}

unittest {
    import std.traits;
    static assert(getSymbolsByUDA!(Test,UDA).length == 0);
}

This fails with:
/usr/include/dlang/dmd/std/traits.d(6721): Error: array index [0] is outside
array bounds [0 .. 0]
/usr/include/dlang/dmd/std/traits.d(6726): Error: template instance
std.traits.getSymbolsByUDA!(Test, UDA).toSymbols!() error instantiating


The issue is that toSymbols within getSymbolsByUDA does not handles case with 0
matches. I think simple change to something like this should work:

 template toSymbols(names...) {
        static if (names.length == 0)
            toSymbols = AliasSeq!();
        else
            mixin("alias toSymbols = AliasSeq!(symbol.%s,
toSymbols!(names[1..$]));"
                  .format(names[0]));
 }

--
Apr 04 2016