Bug 19344 – Enum member UDAs & getUDAs throwing an error
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-10-30T22:59:47Z
Last change time
2020-05-20T01:05:07Z
Assigned to
No Owner
Creator
Daniel Čejchan
Comments
Comment #0 by czdanol — 2018-10-30T22:59:47Z
Having the following code:
import std.traits;
struct A {
int func;
}
enum E {
@A(0) a
}
pragma(msg, getUDAs!(E.a, A));
I get:
onlineapp.d(8): Error: undefined identifier A
onlineapp.d(11): Error: template instance `std.traits.getUDAs!(cast(E)0, A)` error instantiating
onlineapp.d(11): while evaluating pragma(msg, getUDAs!(cast(E)0, A))
Comment #1 by mrsmith33 — 2019-11-17T17:24:05Z
Have the same bug. Example:
---
import std.traits : getUDAs;
void main(){}
struct Struct {
int value;
}
enum Enum {
@Struct(42) first,
}
static assert(getUDAs!(Enum.first, Struct)[0] == Struct(42));
static assert(__traits(getAttributes, Enum.first)[0] == Struct(42)); // this version always works
---
app.d(7): Error: undefined identifier Struct
app.d(9): Error: template instance std.traits.getUDAs!(cast(Enum)0, Struct) error instantiating
app.d(9): while evaluating: static assert((__error)[0] == Struct(42))
However if I swap static asserts it compiles:
---
import std.traits : getUDAs;
void main(){}
struct Struct {
int value;
}
enum Enum {
@Struct(42) first,
}
static assert(__traits(getAttributes, Enum.first)[0] == Struct(42));
static assert(getUDAs!(Enum.first, Struct)[0] == Struct(42));
---
Comment #2 by boris2.9 — 2020-05-19T14:04:45Z
*** This issue has been marked as a duplicate of issue 20835 ***
Comment #3 by dlang-bot — 2020-05-20T01:05:07Z
dlang/dmd pull request #11163 "Fix issue 20835 - Enum member attributes being evaluated in wrong scope." was merged into stable:
- d76f8c37f637e9b393eef0306c4467566e1044fd by Boris Carvajal:
Fix Issues 20835, 19344 - Enum member attributes being evaluated in wrong scope.
https://github.com/dlang/dmd/pull/11163