[Dlang-internal] foreach + ref bug

ketmar ketmar at ketmar.no-ip.org
Thu Jun 28 12:09:48 UTC 2018


Andrea Fontana wrote:

> Thank you! Not that obvious for me, I've just started watching at dmd 
> code.
> Now the question is: should we accept foreach(ref) for non-ref ranges?
>
> IMHO the right thing to do is to reject that code.

i don't see a good reason to do it. the only thing it does is forces a user 
to write alot of duplicated code: basically, exactly the same boilerplate, 
but one with ref, and one without ref. which, in turn, leads either to 
string mixin abuse (and impossibility of debugging/syntax highlighting), or 
to inevitable bugs from copy/paste.

this problem has no nice solution if we'll add code-generating templates to 
the picture, but just silently dropping `ref` causes much less headache, i 
believe.


More information about the Dlang-internal mailing list