[Issue 3332] Mixin a constructor with a construct already present fails

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 10 13:06:14 UTC 2019


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #8 from RazvanN <razvan.nitu1305 at gmail.com> ---
For a normal function, the mixin can be named as explicitly inserted in the
overload set:

template C ()
{
    void fun(int i)
    {

    }
}

class A
{
    mixin C f;
    alias fun = f.fun;

    void fun ()
    {

    }
}

void main ()
{
    auto a = new A();
    a.fun();
}

However, for constructors you cannot do that since you do not have a name. I
tried using __ctor:

  template C ()
  {
      this (int i)
      {   
  ·······
      }   
  }

  class A
  {
      mixin C f;
      alias __ctor = f.__ctor;   // alias `test.A.__ctor` is not a 
                                 //   constructor; identifiers starting
                                 //   with `__` are reserved for the
implementation                                                                  
  ····
      this ()
      {   
      }   
  }

  void main ()
  {
      auto a = new A(3);
  }

But get the above mentioned error. The solution would be to allow the usage of
__ctor in this situation.

--


More information about the Digitalmars-d-bugs mailing list