Skip to content

Commit

Permalink
Fixed Issue 16387
Browse files Browse the repository at this point in the history
(getSymbolsByUDA works with structs but fails with classes)

- added a filter to skip the inaccessable 'this' member
  • Loading branch information
togrue authored and togrue committed Aug 29, 2016
1 parent 1d48fb9 commit b44e3bd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions std/traits.d
Expand Up @@ -6956,9 +6956,12 @@ template getSymbolsByUDA(alias symbol, alias attribute) {
.format(names[0]));
}

enum hasSpecificUDA(string name) = mixin("hasUDA!(symbol.%s, attribute)".format(name));
// filtering out nested class context
enum noThisMember(string name) = (name != "this");
alias membersWithoutNestedCC = Filter!(noThisMember, __traits(allMembers, symbol));

alias membersWithUDA = toSymbols!(Filter!(hasSpecificUDA, __traits(allMembers, symbol)));
enum hasSpecificUDA(string name) = mixin("hasUDA!(symbol.%s, attribute)".format(name));
alias membersWithUDA = toSymbols!(Filter!(hasSpecificUDA, membersWithoutNestedCC));

// if the symbol itself has the UDA, tack it on to the front of the list
static if (hasUDA!(symbol, attribute))
Expand Down Expand Up @@ -7042,6 +7045,20 @@ template getSymbolsByUDA(alias symbol, alias attribute) {
static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[1], Attr));
}

// #16387: getSymbolsByUDA works with structs but fails with classes
unittest
{
enum Attr;
class A
{
@Attr uint a;
}

alias res = getSymbolsByUDA!(A, Attr);
static assert(res.length == 1);
static assert(res[0].stringof == "a");
}

/**
Returns: $(D true) iff all types $(D T) are the same.
*/
Expand Down

0 comments on commit b44e3bd

Please sign in to comment.