@@ -8812,6 +8812,43 @@ template getSymbolsByUDA(alias symbol, alias attribute)
8812
8812
static assert (is (getSymbolsByUDA! (X, X) == AliasSeq! ()));
8813
8813
}
8814
8814
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
+
8815
8852
// getSymbolsByUDA produces wrong result if one of the symbols having the UDA is a function
8816
8853
// https://issues.dlang.org/show_bug.cgi?id=18624
8817
8854
@safe unittest
@@ -8866,7 +8903,11 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)
8866
8903
alias member = __traits(getMember, symbol, names[0 ]);
8867
8904
8868
8905
// 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; }))
8870
8911
{
8871
8912
alias getSymbolsByUDAImpl = tail;
8872
8913
}
0 commit comments