ldc/tests/codegen/array_catassign_gh2588.d
Martin Kinkelin f0aba4559f
Fix cat-assign-element issue if rhs affects the lhs length (#2589)
I.e., this fixes #2588.

To fix the index of the new array element to be assigned to, I went for
decrementing the new length instead of saving the old length directly
before the druntime call (i.e., after evaluating the rhs expression due
to its potential side effects). The IR seems more intuitive to me this
way - load both new length+ptr directly after the druntime call and then
decrement the length by 1.
2018-02-23 18:51:36 +01:00

14 lines
181 B
D

// RUN: %ldc -run %s
int work(ref int[] array)
{
array ~= 123;
return 456;
}
void main()
{
int[] array;
array ~= work(array);
assert(array == [ 123, 456 ]);
}