struct Dependency {
string name;
}
enum {
Dependency[] dependencies = [
{ name: "foo" }
]
}
void main() {}
onlineapp.d(7): Error: found `}` when expecting `;` following statement
Comment #1 by b2.temp — 2021-06-21T06:54:00Z
This is not supposed to work actually, so changed the importance to enhancement.
By [1] the construct exepected here is
```ebnf
Type Identifier "=" AssignExpression
```
while struct initializer is part of another rule, i.e Initializer ([2])
The enhancement would be to have
```ebnf
Type Identifier "=" Initializer
```
[1] https://dlang.org/spec/enum.html#AnonymousEnumMember
[2] https://dlang.org/spec/declaration.html#Initializer
Comment #2 by maxsamukha — 2021-06-21T07:51:52Z
(In reply to Basile-z from comment #1)
> This is not supposed to work actually, so changed the importance to
> enhancement.
>
I don't agree that is an enhancement.
https://dlang.org/spec/enum.html#manifest_constants: "If there is only one member of an anonymous enum, the { } can be omitted. Gramatically speaking, this is an AutoDeclaration."
That is, the following two are supposed to be consistent, but only the former compiles:
enum Dependency[] dependencies = [
{ name: "foo" }
];
enum {
Dependency[] dependencies = [
{ name: "foo" }
]
}
Why are enum members initialized with AssignExpression instead of Initializer? If there is no reason other than historical, it is a bug.
Comment #3 by b2.temp — 2021-06-21T09:30:21Z
yeah you're right, there's is a fog here. I missed the point when following strictly the grammar and ignoring the desciption.
restored to a normal bug ;)
Comment #4 by robert.schadek — 2024-12-13T19:17:16Z