When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"
realhet
real_het at hotmail.com
Fri Sep 12 09:17:10 UTC 2025
On Friday, 12 September 2025 at 08:44:47 UTC, Stefan Koch wrote:
> On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote:
Hi, thanks for quick answer!
When I turn the string mixin into a statement by putting a `;` at
its end, the
enum bla = `(){return 4;}();`
`mixin(bla);` Case works perfectly. It just drops its return
statement;
But now the expression variant drops an error:
`auto x = mixin(bla);`
```
Error: unexpected token `;` after call expression
while parsing string mixin expression
```
So my problem is that before 1.41 both versions went fine with
the expr mixin template.
enum bla = `(){return 4;}();`;
mixin(bla); //Compiles, drops the return value
auto x = mixin(bla); //Compiles, stores the return value in
variable `x`
At this point of understanding, I can solve this in a manual way
by using 2 string mixins: an expression mixin and a statement
mixin. I'm only a bit sad, that in the past it was fully
automatic.
I think back then compiler verified it the mixin is a statement
or an expression at a later state.
But now as you said, it expects one of them by checking the place
of mixin insertion:
- if it finds an `=`, then it must be a mixin expression. <-
this expectation is valid
- if it does not find an `=`, then it must be a mixin statement.
<- Now this is bad, because `xxx;` xxx can be BOTH a mixin
statement and a mixin expression(with side effects and unused
return value).
(BTW, I was a bit angry, but I really should not! This is
precious learning :D)
More information about the Digitalmars-d-learn
mailing list