[Issue 21352] enum members should not be given UDAs of its parent enum declaration

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 1 04:21:22 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21352

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #3 from RazvanN <razvan.nitu1305 at gmail.com> ---
(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.

--


More information about the Digitalmars-d-bugs mailing list