"Walter Bright" <[email protected]> wrote in message 
news:[email protected]...
> The issue is what if b is a property, returns a temporary object, and that 
> temp's .c field is uselessly set to 3?
>
> It's a classic problem with properties that are implemented as functions.
>
> I don't see how C#'s special property syntax adds any value for dealing 
> with this.
>
> One thought I had was to simply disallow the '.' to appear after a 
> function style property.

Disallow it by default. IE.

a.b.c.d = 3;

If any of those return an rvalue / temporary then it should be an error to 
assign to it.

However we should not disallow...

int i = a.b.c.d.e.f;

But we should also find a way to let the programmer tell the compiler if it 
is ok for it to rewrite...

a.b.c = 3;

as

B tmp = a.b;
tmp.c = 3;
a.b = tmp;

perhaps an extra operator   opSubAssign()   Which tells the compiler it's ok 
to rewrite the the assignment using temporrarys and reassignment.

class A
{
    B _b;
    void b.opAssign(ref B bbb) { _b = bbb; }
    void b.opSubAssign(ref B bbb) { opAssign(bbb); }
}

Then the programmer could also write an specialized subassignment.
 


Reply via email to