Skip to content

Commit

Permalink
Fix Issue 23977 - [REG2.102] cannot use getSymbolsByUDA on template s…
Browse files Browse the repository at this point in the history
…truct with alias member
  • Loading branch information
RazvanN7 committed Jun 29, 2023
1 parent 65e380c commit 9976964
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -8812,6 +8812,43 @@ template getSymbolsByUDA(alias symbol, alias attribute)
static assert(is(getSymbolsByUDA!(X, X) == AliasSeq!()));
}

@safe pure nothrow @nogc unittest
{
// https://issues.dlang.org/show_bug.cgi?id=23776
struct T
{
struct Tag {}
@Tag struct MyStructA {}
@Tag struct MyStructB {}
@Tag struct MyStructC {}
}
alias tcomponents = getSymbolsByUDA!(T, T.Tag);
static assert(tcomponents.length > 0);

struct X
{
struct Tag {}
@Tag enum MyEnumA;
@Tag enum MyEnumB;
@Tag enum MyEnumC;
}
alias xcomponents = getSymbolsByUDA!(X, X.Tag);
static assert(xcomponents.length > 0);


// https://issues.dlang.org/show_bug.cgi?id=23977
struct S(string str)
{
alias strstr = str;

int i;
}

static struct A {}

assert((getSymbolsByUDA!(S!("a"), A)).length == 0);
}

// getSymbolsByUDA produces wrong result if one of the symbols having the UDA is a function
// https://issues.dlang.org/show_bug.cgi?id=18624
@safe unittest
Expand Down Expand Up @@ -8866,7 +8903,11 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)
alias member = __traits(getMember, symbol, names[0]);

// Filtering not compiled members such as alias of basic types.
static if (isAliasSeq!member || isType!member)
static if (isAliasSeq!member ||
// exclude basic types and derived types
(isType!member && !isAggregateType!member && !is(member == enum)) ||
// exclude aliases to expressions such as string literals
__traits(compiles, { auto ex = member; }))
{
alias getSymbolsByUDAImpl = tail;
}
Expand Down

0 comments on commit 9976964

Please sign in to comment.