This code doesn't work: -------------------------------------- import std.traits; enum B; void main() { enum A; struct S { @A int a; } enum E { @A a, @B b } static assert(hasUDA!(S.a, A)); // Error: undefined identifier A ... while evaluating: static assert(hasUDA!(E.a, A)); static assert(hasUDA!(E.b, B)); static assert(is(getUDAs!(S.a, A)[0] : A)); // Error: static assert: is(getUDAs!(cast(E)0, A)[0] : A) is false static assert(is(getUDAs!(E.a, A)[0] : A)); static assert(is(getUDAs!(E.b, B)[0] : B)); static assert(getSymbolsByUDA!(S, A).length == 1); // Error: static assert: 0LU == 1LU is false //static assert(getSymbolsByUDA!(E, A).length == 1); static assert(getSymbolsByUDA!(E, B).length == 1); } -------------------------------------- The following issue is similar, but the previous example succeeds in S, but fails in E. https://issues.dlang.org/show_bug.cgi?id=15335
Reduced: unittest { enum A; enum E { @A a } pragma(msg, getAllUDAs!(E.a)); } alias getAllUDAs(A...) = __traits(getAttributes, A); By introducting a symbol A at module scope we can even have getAllUDAs return the wrong thing. Obviously it's looking up things in the wrong scope.
@BorisCarvajal created dlang/dmd pull request #11527 "Fix Issue 21122 - __traits(getAttributes) wrong scope on enums" fixing this issue: - Fix Issue 21122 - __traits(getAttributes) wrong scope on enums https://github.com/dlang/dmd/pull/11527
dlang/dmd pull request #11527 "Fix Issue 21122 - __traits(getAttributes) wrong scope on enums" was merged into stable: - 0ad9333f5dda9b857c51317c9be51039e8b91716 by Boris Carvajal: Fix Issue 21122 - __traits(getAttributes) wrong scope on enums https://github.com/dlang/dmd/pull/11527
dlang/dmd pull request #11542 "merge stable" was merged into master: - 7d40b941b2b36ee84aa669f9c5310e1b98caa504 by Boris Carvajal: Fix Issue 21122 - __traits(getAttributes) wrong scope on enums https://github.com/dlang/dmd/pull/11542