[Issue 16426] Templated opAssign do not forward on Alias this.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 22 19:46:50 UTC 2018


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

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

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

--- Comment #1 from John Hall <john.michael.hall at 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
}

--


More information about the Digitalmars-d-bugs mailing list