When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"
Stefan Koch
uplink.coder at googlemail.com
Fri Sep 12 08:44:47 UTC 2025
On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote:
> Hi,
>
> ```d
> import std;
>
> void main() {
> int val = 4;
> enum prog = q{
> (){ val += 1; return val; }()
> };
> //mixin(prog); //
> auto dummy = mixin(prog); //Must capture the return value,
> otherwise it hallucinates EOF.
> writeln(val);
> }
> ```
>
> When uncommenting mixin(prog);
> It gives
> ```
> Error: found `End of File` when expecting `;` following
> expression
> expression: `()
> {
> val += 1;
> return val;
> }
> ()`
> ```
Hi realhet,
I can explain what happens here.
When you write `auto x = mixin(bla);`
The mixin it parsed as an expression.
b/c there can only be an expression after the =.
However when you don't do that the mixin is parsed as a
statement, after which a ; is expected and mandatory.
putting a ; into the string generated by prog should fix that.
More information about the Digitalmars-d-learn
mailing list