[Issue 21175] opAssign should be allowed to return void and let the compiler take care of chained assignments

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 19 00:45:15 UTC 2020


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

Paul Backus <snarwin+bugzilla at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |snarwin+bugzilla at gmail.com

--- Comment #1 from Paul Backus <snarwin+bugzilla at gmail.com> ---
I think a lowering that works for all cases is

    e1 = e2

to

    auto ref typeof(e1) (auto ref typeof(e1) v1) {
        v1.opAssign(e2);
        return v1;
    }(e1)

This can be expanded recursively to handle any number of chained assignments
(e.g., replace e2 with `e2a = e2b`).

The only catch is that D doesn't currently allow function literals that return
`auto ref`.

--


More information about the Digitalmars-d-bugs mailing list