Bug 21122 – __traits(getAttributes) wrong scope on enums
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-05T12:09:35Z
Last change time
2020-08-10T12:09:40Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
SHOO
Comments
Comment #0 by zan77137 — 2020-08-05T12:09:35Z
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
Comment #1 by simen.kjaras — 2020-08-05T13:07:57Z
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.
Comment #2 by dlang-bot — 2020-08-07T02:36:18Z
@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
Comment #3 by dlang-bot — 2020-08-07T03:36:51Z
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
Comment #4 by dlang-bot — 2020-08-10T12:09:40Z
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