opAssign(int) necessitates this(this) for automatic opAssign to work

Ali Çehreli acehreli at yahoo.com
Sat Dec 26 16:42:07 PST 2009


I've tested the following with dmd 2.037.

The compiler generated opAssign is disabled by the definition of 
opAssign(int). The compiler rejects the following assignment operation. 
(The error message is in the comment below.)

Is this by design?

When I also define post-blit, the compiler generated opAssign is 
available again and seems to work correctly. (My struct doesn't have any 
members for brevity.)

The program below compiles when this(this) is provided.

void main()
{
     S s0;
     s0 = s0;    // ERROR
}

struct S
{
     /*
       1) Define just opAssign(int); the compiler rejects the code:

        Error: function deneme.S.opAssign (int) is not callable
               using argument types (S)

        Error: cannot implicitly convert expression (s0) of
               type S to int
     */
     ref S opAssign(int)
     {
         return this;
     }

     /*
       2) Uncomment post-blit; the above error disappears and
          the compiler generated opAssign works as expected
      */
//     this(this)
//     {}
}

What is the logic behind it?

Thank you,
Ali



More information about the Digitalmars-d mailing list