Ping? I added a similar test case which also produces wrong code with DMD to Bugzilla: <a href="http://d.puremagic.com/issues/show_bug.cgi?id=8957">http://d.puremagic.com/issues/show_bug.cgi?id=8957</a><div><br></div><div>
David</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Sep 15, 2012 at 9:26 PM, David Nadlinger <span dir="ltr"><<a href="mailto:code@klickverbot.at" target="_blank">code@klickverbot.at</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">As far as I understand, Expression::apply is meant to iterate over any<br>
and all of the subexpressions "contained" in an Expression. This is<br>
the way it is used, for example, in Expression::toDelegate to<br>
determine the variables referenced from lazy arguments that are turned<br>
into delegates.<br>
<br>
The problem is that apply doesn't take DeclarationExps into account,<br>
which can also contain expressions (e.g. in form of a VarDeclaration<br>
initializer).<br>
<br>
A problem caused by this occurs with lazy parameters of a type with a<br>
postblit, for which a temporary is internally declared via a rewrite<br>
to a comma expression containing a variable declaration wrapped in a<br>
Declaration. If the parameter is a variable in the outer scope, this<br>
actually leads to the nested reference to it not being detected. For a<br>
test case and a quick-and-dirty workaround, see<br>
<a href="https://github.com/ldc-developers/ldc/blob/master/dmd2/delegatize.c#L117" target="_blank">https://github.com/ldc-developers/ldc/blob/master/dmd2/delegatize.c#L117</a><br>
(the example in question actually seems to work fine with DMD, but I<br>
don't think it would be hard to come up with a test case where a<br>
closure would be needed, but is not allocated due to this).<br>
<br>
The above is obviously only a quick hack to fix this very specific<br>
case for LDC, but I'm not sure what the correct solution for the<br>
problem is. At first, I tried to implement the<br>
VarDeclaration->ExpInitializer check in a new DeclarationExp::apply,<br>
but it lead to a bunch of "not available at compile time" errors in<br>
CTFE.<br>
<br>
Could somebody confirm what the intended behavior of Expression::apply<br>
is? If DeclarationExps should be taken into account in the general, I<br>
could submit a pull request for that and work with Don to investigate<br>
the CTFE errors, but I'm not 100% sure that this is really an<br>
oversight.<br>
<span class="HOEnZb"><font color="#888888"><br>
David<br>
</font></span></blockquote></div><br></div>