D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19237 - string mixin struct initializer doesn't compile
Summary: string mixin struct initializer doesn't compile
Status: RESOLVED DUPLICATE of issue 15692
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-10 10:09 UTC by RR
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description RR 2018-09-10 10:09:52 UTC
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 basile-z 2019-12-12 20:18:43 UTC
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 ***