www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21175] New: opAssign should be allowed to return void and let

https://issues.dlang.org/show_bug.cgi?id=21175

          Issue ID: 21175
           Summary: opAssign should be allowed to return void and let the
                    compiler take care of chained assignments
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andrei erdani.com

The return value of opAssign should always be `this` of type `ref T`. Literally
anything else is a bug, and that makes for a poor convention. The compiler
should take care of all that. Means user code is free of the convention and can
return void.

Chained assignments should be lowered as follows. Currently e1 = e2 = e3 is
lowered as:

e1.opAssign(e2.opAssign(e3))

It should be lowered as:

(ref T x) { x.opAssign(e3); e1.opAssign(x); }(e2)

meaning e2 is evaluated first, then e3 is evaluated and assigned to (the result
of evaluating) e2, then then x is assigned to (the result of evaluating) e1.

--
Aug 18 2020