www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16364] New: getUDAs and hasUDA do not give consistent results

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

          Issue ID: 16364
           Summary: getUDAs and hasUDA do not give consistent results
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: issues.dlang jmdavisProg.com

Take this code

import std.traits;

void main()
{
    struct AttrT(T)
    {
        string name;
        T value;
    }

     AttrT!int("Answer", 42) int a;
    static assert(getUDAs!(a, AttrT).length == 1);
    static assert(getUDAs!(a, AttrT!int).length == 1);
    //static assert(hasUDA!(a, AttrT));
    static assert(hasUDA!(a, AttrT!int));

     ("alpha") int b;
    //static assert(getUDAs!(b, "alpha").length == 1);
    static assert(hasUDA!(b, "alpha"));
}

If either of the commented lines are uncommented, you get a compiler error.
getUDAs is able to handle checking for UDAs which are templates without
checking for a specific instantiation, whereas hasUDA is not, and hasUDA is
able to check for UDAs that are values, wherea getUDAs cannot.

It seems to me that the thing to do would be to make getUDAs handle all of the
cases appropriately and then just make hasUDA use getUDAs. It would mean less
code duplication and ensure that they the behave the same.

--
Aug 08 2016