On Sunday, 24 March 2019 at 18:18:39 UTC, sighoya wrote:
Hmm..., sounds like bad news. Is there any mixin technology for statements?

mixin() works for statements too.

It is the *context* though. If mixin() appears where the compiler expects an expression, it must give an expression. Ditto for statements (and for declarations btw). Consider

int main() {
   // compiler expecting a statement here, so
   mixin("if(true) {}"); // allowed

   // but here it is expecting an expression
   return mixin("some_expression");
}

This is also the reason why mixin sometimes requires ; and sometimes requires a LACK of ;

int main() {
   int a;
   mixin("a = 10;"); // the ; inside the mixin is required there
   return mixin("a"); // but mixin("a;"); there would be an error
}


Think of mixin() not as pasting code per se, but pasting an AST node inside the compiler's data structures. It must be a complete node of that tree that can be substituted in.

Reply via email to