D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6399 - [CTFE] struct member array.length -= x doesn't work, while array[0..$-x] works
Summary: [CTFE] struct member array.length -= x doesn't work, while array[0..$-x] works
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-29 07:05 UTC by Dmitry Olshansky
Modified: 2011-07-31 12:10 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dmitry Olshansky 2011-07-29 07:05:49 UTC
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 Don 2011-07-30 14:03:03 UTC
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.