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: [email protected]
Reporter: [email protected]
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.
--