Thread overview
[Issue 16426] Templated opAssign do not forward on Alias this.
Mar 22, 2018
John Hall
Oct 24, 2018
RazvanN
Oct 25, 2018
RazvanN
Dec 17, 2022
Iain Buclaw
March 22, 2018
https://issues.dlang.org/show_bug.cgi?id=16426

John Hall <john.michael.hall@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john.michael.hall@gmail.com

--- Comment #1 from John Hall <john.michael.hall@gmail.com> ---
Structs have opAssign defined by default. Alias this only forwards undefined lookups. Below is a workaround.

import std.stdio : writeln;

struct Base{
        void opAssign(T)(T x){
                writeln("assigning : ",x);
        }
}
struct Derived{
        Base parent;
        alias parent this;

        void opAssign(T)(T x){
                parent = x;
        }
}

void main()
{
        Base a;
        a = 10; //ok

        Derived b;
        b = 20; //Error
}

--
October 24, 2018
https://issues.dlang.org/show_bug.cgi?id=16426

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |INVALID

--
October 25, 2018
https://issues.dlang.org/show_bug.cgi?id=16426

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--
September 04, 2020
https://issues.dlang.org/show_bug.cgi?id=16426

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Ran into this today.

If the compiler is going to generate an opAssign, it should generate one that forwards to the alias-this member. It should be something equivalent to adding the following overload to the existing generated opAssign:

auto ref opAssign(T)(auto ref T val) if (!is(T == typeof(this)) &&
__traits(compiles, aliasThisMember = val))
{
   aliasThisMember = val;
}

BTW, thanks for the workaround. For a wrapped single alias-this member, it works perfectly.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=16426

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--