Property assignment problem

SebastianA sebastian.ahlman at remedygames.com
Thu May 10 23:52:14 PDT 2012


This is related to this thread: 
http://forum.dlang.org/thread/cnwpmhihmckpjhlaszzy@forum.dlang.org

I am posting it here as well, since it no longer concerns only 
GDC. Also, I am not sure if this is a bug or intended behaviour. 
Consider the following code:

====
void runTest()
{
	Thing t;
	t.vPosition = (Clock.currStdTime % 2 == 0) ? Vec(2, 2) : Vec(3, 
3);
	Vec v = t.vPosition;

	writefln("%d %d\n", v.x, v.y);
}

struct Vec
{
	int x;
	int y;
}

struct Thing
{
	@property Vec vPosition() { return mPosition; }
	@property Vec vPosition( const ref Vec value ) { return 
mPosition = value; }

private:
	Vec mPosition;
}
====

The line that sets the value of the vPosition property does not 
compile on DMD. Instead it gives the error "Error: not a property 
t.vPosition". On GDC this compiles but it does not work in 
release mode, only in debug mode. In release mode it sets the 
property to 0 0. If I assign the vector to a temp variable before 
assigning it to the position it works. It also works if I replace 
the time expression with a constant like "true" or some other 
value known at compile time.

Is this a bug or is it supposed to refuse to compile the code? 
Also, why does it compile on GDC?

BR,
Sebastian Ahlman


More information about the Digitalmars-d mailing list