Why is this not allowed?

ryuukk_ ryuukk.dev at gmail.com
Tue Oct 8 15:10:54 UTC 2024


On Monday, 7 October 2024 at 18:06:30 UTC, Steven Schveighoffer 
wrote:
> On Sunday, 6 October 2024 at 05:41:10 UTC, ryuukk_ wrote:
>> There is no new syntax to invent
>>
>> instead of writing this error:
>> ```
>> onlineapp.d(8): Error: no identifier for declarator `stats`
>> ```
>>
>> you generate a random identifier and assign it
>>
>> ```D
>>     extern(D) static Identifier 
>> generateAnonymousId(const(char)[] name)
>> ```
>>
>> https://github.com/dlang/dmd/blob/master/compiler/src/dmd/identifier.d#L165
>>
>> I'm very far from being bright, but i know simple logic
>
> The problem is not the ability to generate an id, the problem 
> is that the declaration is over. Anything after the closing 
> brace is a *new declaration*.
>
> Whitespace is not significant in D, so you have to invent a new 
> syntax to to mean the declaration continues.
>
> D sees this:
>
> ```d
> struct {
>   int x;
>   int y;
> } something;
> ```
>
> as this:
>
> ```d
> struct {
>   int x;
>   int y;
> }
> // DECLARATION OF ANONYMOUS STRUCT OVER.
>
> something;  // this is something different, unrelated to the 
> struct above.
> ```
>
> One declaration defines an anonymous struct, and one that is a 
> new declaration `something;`. Or if you are in a function, 
> `something;` is treated as a statement.
>
> You can't change existing syntax, as that would break code, so 
> you need new syntax.
>
> C allows this because structs are *required* to end with a 
> semicolon. So the compiler knows the thing after the brace is 
> part of the same declaration.
>
> -Steve

Nonono, you overthink it

Store last anonamous struct

When you see a field without a type, you assign it with that 
anonymous struct

D people love to complicate everything

Keep things simple and solve people's problem

Stop trying to write essays about simple stuff

ALl the languages have solved this, D will now have move 
constructor lol, yet can't do basics well


More information about the Digitalmars-d-learn mailing list