Bug 6399 – [CTFE] struct member array.length -= x doesn't work, while array[0..$-x] works
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-07-29T07:05:00Z
Last change time
2011-07-31T12:10:06Z
Assigned to
nobody
Creator
dmitry.olsh
Comments
Comment #0 by dmitry.olsh — 2011-07-29T07:05:49Z
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);
Comment #1 by clugdbug — 2011-07-30T14:03:03Z
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.