Bug 21352 – enum members should not be given UDAs of its parent enum declaration
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-10-31T08:47:03Z
Last change time
2021-01-07T16:20:18Z
Keywords
pull
Assigned to
No Owner
Creator
SHOO
Comments
Comment #0 by zan77137 — 2020-10-31T08:47:03Z
This code is broken:
--------------------------------
@("aaa") enum Hoge {
@("bbb") foo, // tuple("aaa", "bbb") -> should be only tuple("bbb")
bar, // tuple()
}
@("aaa") struct Fuga {
@("bbb") int foo; // tuple("bbb")
int bar; // tuple()
}
static assert([__traits(getAttributes, Hoge.foo)] == ["bbb"]); //NG
static assert([__traits(getAttributes, Hoge.bar)] == []);
static assert([__traits(getAttributes, Fuga.foo)] == ["bbb"]);
static assert([__traits(getAttributes, Fuga.bar)] == []);
--------------------------------
Comment #1 by b2.temp — 2020-10-31T08:53:26Z
I hope the new title is ok as the old one was slightly ambiguous
Comment #2 by dlang-bot — 2020-10-31T11:37:28Z
@BorisCarvajal created dlang/dmd pull request #11917 "Fix Issue 21352 - enum members should not be given UDAs of its parent…" fixing this issue:
- Fix Issue 21352 - enum members should not be given UDAs of its parent enum declaration
https://github.com/dlang/dmd/pull/11917
Comment #3 by razvan.nitu1305 — 2020-11-01T04:21:22Z
(In reply to SHOO from comment #0)
> This code is broken:
> --------------------------------
> @("aaa") enum Hoge {
> @("bbb") foo, // tuple("aaa", "bbb") -> should be only tuple("bbb")
> bar, // tuple()
> }
> @("aaa") struct Fuga {
> @("bbb") int foo; // tuple("bbb")
> int bar; // tuple()
> }
> static assert([__traits(getAttributes, Hoge.foo)] == ["bbb"]); //NG
> static assert([__traits(getAttributes, Hoge.bar)] == []);
> static assert([__traits(getAttributes, Fuga.foo)] == ["bbb"]);
> static assert([__traits(getAttributes, Fuga.bar)] == []);
> --------------------------------
I am not convinced this is the right fix. From the spec: "If there are multiple UDAs in scope for a declaration, they are concatenated" and the example given is:
@(1)
{
@(2) int a; // has UDAs (1, 2)
@("string") int b; // has UDAs (1, "string")
}
From this it seems that if the declaration introduces a scope, then the UDA is going to be propagated to the subsequent declarations. From my perspective, the real bug is that:
@("aaa") struct Fuga {
@("bbb") int foo; // tuple("bbb")
int bar; // tuple()
}
static assert([__traits(getAttributes, Fuga.foo)] == ["bbb"]); // should be tuple("aaa", "bbb")
Since applying any qualifier to the struct declaration propagates it to all the declarations in the structm why woud UDAs be
any different? I haven't found anything specifically in the spec that would point that this PR is the right fix, but maybe I am missing something.
Comment #4 by dlang-bot — 2021-01-07T16:20:18Z
dlang/dmd pull request #11917 "Fix Issue 21352 - enum members should not be given UDAs of its parent…" was merged into master:
- 7c990f6061b1ea149fd68bc38eafab19ff8406b9 by Boris Carvajal:
Fix Issue 21352 - enum members should not be given UDAs of its parent enum declaration
https://github.com/dlang/dmd/pull/11917