Bug 19237 – string mixin struct initializer doesn't compile

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-09-10T10:09:52Z
Last change time
2020-03-21T03:56:36Z
Assigned to
No Owner
Creator
Radu Racariu

Comments

Comment #0 by radu.racariu — 2018-09-10T10:09:52Z
The following, will not compile ``` struct S { int i; } void main() { S s = mixin(`{1}`); } ``` Error: found } when expecting ; following statement app.d-mixin-8(8): Error: found End of File when expecting } following compound statement But this will compile: ``` struct S { int i; } void main() { S s = mixin(`S(1)`); } ``` I think the initializer should compile, as array initializers are allowed in the mixin, for example this works: ``` struct S { int i; } void main() { S[] s = mixin(`[S(1), S(2)]`); } ```
Comment #1 by b2.temp — 2019-12-12T20:18:43Z
arrays work but not in the path you think it actually does. auto a = mixin("[0]"); gives an "ExpInitializer" made of a "MixinExpression", which contains some code for a "PrimaryExp" that's a "ArrayLiteral". S s = mixin("{0}"); Is rejected because "StructInitializer" is not a primary exp. When can see then that the requested feature is then part of a bigger project, that if done, handles also this specific case. *** This issue has been marked as a duplicate of issue 15692 ***