Properties: a.b.c = 3

Benji Smith dlanguage at benjismith.net
Thu Jul 30 18:42:40 PDT 2009


Jarrett Billingsley wrote:
> The issue is that the compiler accepts
> no-effect modifications of temporary values as valid statements.
> There is no setter being invoked here, nor should there be.
> 
> Or should there?  In the face of a value type, should the compiler
> rewrite this code as
> 
> auto t = a.b();
> t.c = 3;
> a.b = t;
> 
> ?  The last line of the rewrite is unnecessary if a.b() returns a
> reference type or a byref struct.  But is this what people would
> expect to happen?

I think the compiler should only rewrite the code (as above) if a.b() 
returns a struct, by value. The compiler can figure that out easily 
enough. Depending on the return types of all the different properties in 
a.b.c.d.e.f = 3, there might be a few ref types and a few value types 
returned. Each of those subexpressions would be rewritten with the 
appropriate semantics.

--benji



More information about the Digitalmars-d mailing list