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 13:27:53 UTC 2025
On Friday, 12 September 2025 at 12:23:21 UTC, Nick Treleaven
wrote:
> On Friday, 12 September 2025 at 09:17:10 UTC, realhet wrote:
>> 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:
I did a complete 'martix' of these combinations and accidentally
found the way how I did it already in the past. Actually my
things were changed, it's not related to the DMD/LDC version,
sorry for the false suspection.
So the solution is to put the mixin(expr) into a () and then the
expression it will act BOTH an expression with a return value and
a statement with unused return value.
import std;
```d
void main() {
enum expr = `(){return 4;}()`; //expression
(){return 4;}() ; //<- works
auto x = mixin(expr) ; //<- works
auto y = (mixin(expr)); //<- works
//mixin(expr) ; //<- fails. mixin expects statement
(mixin(expr)) ; //<- THIS IS THE WHEY! :D
}
```
note: The expressio must be a lambda, othewise the compiler will
detect no side effects and refuse to use it as a statement.
(x); <- Is not a construct that comes to my mind as useful, but
this was it. This forces the mixin to expect an expression and
not a statement.
Thank You all to for the help!
More information about the Digitalmars-d-learn
mailing list