www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Error in spec: struct init with member names

reply Johan Engelen <j j.nl> writes:
The spec (or DMD frontend) is broken regarding struct 
initialization with explicit mention of member field names:
https://dlang.org/spec/struct.html#static_struct_init

The spec says:
"The static initializer syntax can also be used to initialize 
non-static variables, provided that the member names are not 
given."

But this code compiles correctly:
```
struct S { int a; int b; int c; int d = 7;}
void test(int i)
{
     S q = {a : 1, c : i }; // q.a = 1, q.b = 0, q.c = i, q.d = 7
}
```

I haven't come up with a reason for why it would not be allowed 
to use member names, so I think it is an error in the spec. If 
not, please explain. If yes, please fix the spec.

Thanks!
   Johan
Jul 03
parent Nick Treleaven <nick geany.org> writes:
On Monday, 3 July 2017 at 18:14:43 UTC, Johan Engelen wrote:
 The spec (or DMD frontend) is broken regarding struct 
 initialization with explicit mention of member field names:
 https://dlang.org/spec/struct.html#static_struct_init
I agree, PR: https://github.com/dlang/dlang.org/pull/1794
Jul 04