Does D allow paradoxical code?

Jerry Quinn jlquinn at optonline.net
Thu Mar 25 22:29:31 PDT 2010


What should happen when the following code is compiled?

mixin(vs);
version(v1) {
  const string vs = "version = v2;";
  pragma(msg, "yes");
}
 else {
  const string vs = "version = v1;";
  pragma(msg, "no");
 }

Currently, there's an error saying that vs must be a string.  However, as far as I can tell, the spec says nothing about order affecting module-scope declarations.  So vs should be valid, and once it substitutes in the mixin, you have a cycle where no matter what vs is, vs should be the other value.

If you don't have the conditional compilation and put the declaration of vs after the mixin, it works as expected.

This generally raises the question of what should be the order of evaluation for constructs like mixins, conditional compilation, and CTFE.   Each has the potential to modify the other.

What should be the rule to break the ambiguity?  Or do we leave it implementation-defined?

Thoughts?
Jerry



More information about the Digitalmars-d mailing list