Thread overview
[Issue 22565] Attributes not accepted for empty declaration
Dec 07, 2021
RazvanN
Dec 07, 2021
Stanislav Blinov
Dec 07, 2021
RazvanN
Dec 09, 2021
RazvanN
Dec 17, 2022
Iain Buclaw
December 07, 2021
https://issues.dlang.org/show_bug.cgi?id=22565

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |INVALID

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
There is no such thing as an EmptyDeclaration in D. We do have empty statements, which are an entirely different thing. UDAs can be attached to declarations so it makes no sense to attach an UDA to a statement. Closing as invalid.

--
December 07, 2021
https://issues.dlang.org/show_bug.cgi?id=22565

Stanislav Blinov <stanislav.blinov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |stanislav.blinov@gmail.com
         Resolution|INVALID                     |---

--- Comment #2 from Stanislav Blinov <stanislav.blinov@gmail.com> ---
(In reply to RazvanN from comment #1)

> There is no such thing as an EmptyDeclaration in D.

Spec says there is:

https://dlang.org/spec/grammar.html https://dlang.org/spec/grammar.html#EmptyDeclaration

DeclDef -> AttributeSpecifier -> Attribute DeclarationBlock -> AtAttribute DeclDef -> AtAttribute EmptyDeclaration

--
December 07, 2021
https://issues.dlang.org/show_bug.cgi?id=22565

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
Ok, I was hasty in my judgement, however, I think that empty declarations are there just to have symmetry with empty statements (as you cannot have statements at top level), still I don't see any point in allowing attaching a UDA to an empty declaration.

To be more precise, UDA's are attached to symbols (that are indeed introduced by declarations). As far as I could tell you cannot attach a UDA to an anonymous function or an anonymous class, specifically because it does not have a name.

I guess we can modify the spec to specifically mention that UDAs must be applied to a symbol.

--
December 07, 2021
https://issues.dlang.org/show_bug.cgi?id=22565

--- Comment #4 from Răzvan Ștefănescu <rumbu@rumbu.ro> ---
UDAs can be attached to any declaration according to the grammar, not to a symbol only.

How useful is that, it's debatable, but there are situations where the fact that attributes are attached to declarations, not to a symbol makes a huge difference:

@attr
int a, b, c;

where @attr is applied to a, b and c, not to a only.

Also there is the unittest case where there is no symbol, but attributes can have a meaning and can be obtained using __traits, see https://dlang.org/spec/traits.html#getUnitTests

There are two options:
- dmd must eat his own food by implementing the existing grammar specification
or,
- the grammar must be adjusted to match the current situation;

Tizule, iute ești mă la mânie, ia-o mai ușor :)

--
December 09, 2021
https://issues.dlang.org/show_bug.cgi?id=22565

--- Comment #5 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Răzvan Ștefănescu from comment #4)
> UDAs can be attached to any declaration according to the grammar, not to a symbol only.
> 
> How useful is that, it's debatable, but there are situations where the fact that attributes are attached to declarations, not to a symbol makes a huge difference:
> 
> @attr
> int a, b, c;
> 
> where @attr is applied to a, b and c, not to a only.
> 

Yes, but the point is that @attr is applied individually to each of the variable declarations.

> Also there is the unittest case where there is no symbol, but attributes can have a meaning and can be obtained using __traits, see https://dlang.org/spec/traits.html#getUnitTests
> 

Unittests appear to not have a name, but they are actually not any different from any other function (internally, the compiler assigns a name of the form `__unittest_$generate_some_number`).

> There are two options:
> - dmd must eat his own food by implementing the existing grammar
> specification or,
> - the grammar must be adjusted to match the current situation;
> 

I would opt for the later.

> Tizule, iute ești mă la mânie, ia-o mai ușor :)

:))

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=22565

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 13
https://issues.dlang.org/show_bug.cgi?id=22565

--- Comment #6 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/20014

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--