On 05/24/2015 09:30 PM, kinke wrote:
<code>
import core.stdc.stdio;

static int[] _array = [ 0, 1, 2, 3 ];

int[] array() @property { printf("array()\n"); return _array; }
int   start() @property { printf("start()\n"); return 0; }
int   end()   @property { printf("end()\n");   return 1; }

void main()
{
     array[start..end] = 666;
     printf("---\n");
     array[start] = end;
}
</code>

<stdout>
array()
start()
end()
---
start()
array()
end()
</stdout>

So for the 2nd assignment's left-hand-side, the index is evaluated
before evaluating the container! Please don't tell me that's by design. :>

[origin: https://github.com/D-Programming-Language/phobos/pull/3311]

A related issue is that the rewrites documented at http://dlang.org/operatoroverloading.html don't all preserve the order of subexpressions. However, ideally, the order of evaluation would be preserved.

Reply via email to