It has something to do with structs, test case: struct A{ int[] arr; int subLen() { arr = [1,2,3, 4,5]; arr.length -= 1; //replace this line with a next and it compiles // arr = arr[0..$-1]; return arr.length; } } int getMeFour() { A a; return a.subLen(); } int getMeFour2() { auto arr = [1,2,3, 4,5]; arr.length -= 1; return arr.length; } enum t1 = getMeFour(); enum t2 = getMeFour2();//this works regardless of -=x or [0..$-x] static assert(t1 == 4); static assert(t2 == 4);
Actually array.length = array.length - x also works. It's only +=, -= that fail. It's because it gets changed into: (tmp = &array, *(tmp).length = *(tmp.length)-x ); and (*p).length = n; isn't yet implemented.
https://github.com/D-Programming-Language/dmd/commit/7ef3b2bb9e740df39108957ae5e3b2aa8253d351 https://github.com/D-Programming-Language/dmd/pull/284