Skip to content

Commit 9976964

Browse files
committed
Fix Issue 23977 - [REG2.102] cannot use getSymbolsByUDA on template struct with alias member
1 parent 65e380c commit 9976964

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

std/traits.d

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8812,6 +8812,43 @@ template getSymbolsByUDA(alias symbol, alias attribute)
88128812
static assert(is(getSymbolsByUDA!(X, X) == AliasSeq!()));
88138813
}
88148814

8815+
@safe pure nothrow @nogc unittest
8816+
{
8817+
// https://issues.dlang.org/show_bug.cgi?id=23776
8818+
struct T
8819+
{
8820+
struct Tag {}
8821+
@Tag struct MyStructA {}
8822+
@Tag struct MyStructB {}
8823+
@Tag struct MyStructC {}
8824+
}
8825+
alias tcomponents = getSymbolsByUDA!(T, T.Tag);
8826+
static assert(tcomponents.length > 0);
8827+
8828+
struct X
8829+
{
8830+
struct Tag {}
8831+
@Tag enum MyEnumA;
8832+
@Tag enum MyEnumB;
8833+
@Tag enum MyEnumC;
8834+
}
8835+
alias xcomponents = getSymbolsByUDA!(X, X.Tag);
8836+
static assert(xcomponents.length > 0);
8837+
8838+
8839+
// https://issues.dlang.org/show_bug.cgi?id=23977
8840+
struct S(string str)
8841+
{
8842+
alias strstr = str;
8843+
8844+
int i;
8845+
}
8846+
8847+
static struct A {}
8848+
8849+
assert((getSymbolsByUDA!(S!("a"), A)).length == 0);
8850+
}
8851+
88158852
// getSymbolsByUDA produces wrong result if one of the symbols having the UDA is a function
88168853
// https://issues.dlang.org/show_bug.cgi?id=18624
88178854
@safe unittest
@@ -8866,7 +8903,11 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)
88668903
alias member = __traits(getMember, symbol, names[0]);
88678904

88688905
// Filtering not compiled members such as alias of basic types.
8869-
static if (isAliasSeq!member || isType!member)
8906+
static if (isAliasSeq!member ||
8907+
// exclude basic types and derived types
8908+
(isType!member && !isAggregateType!member && !is(member == enum)) ||
8909+
// exclude aliases to expressions such as string literals
8910+
__traits(compiles, { auto ex = member; }))
88708911
{
88718912
alias getSymbolsByUDAImpl = tail;
88728913
}

0 commit comments

Comments
 (0)