@@ -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