alias this leads to compilation error in one of two similar contexts

Ali Çehreli acehreli at yahoo.com
Sun Dec 1 00:32:50 PST 2013


On 11/30/2013 02:18 PM, Carl Sturtivant wrote:
>
> The following is boiled down from a real world context. I'm using dmd
> 2.064.2 Windows. Can someone please explain what's going on.
>
> ================
>
> struct my_integer {
>      int val = 99;
>      alias val this;
>      //this( int n) { val = n; }
> }
>
> struct blah {
>      my_integer Integer;
>
>      this( int n) { Integer = n; }
>      ref blah opAssign( int n) { Integer = n; return this; }
> }
>
> ================
>
> The constructor in blah does not compile unless the constructor in
> my_integer is uncommented. Yet the opAssign function in blah compiles
> just fine.
>
> The error message is
>   Error: cannot implicitly convert expression (n) of type int to my_integer
> and the line causing it is blah's constructor.
>
> This behavior did not exist with dmd 2.063.2 (Windows) --- I reverted to
> check this.
>

At least the discrepancy warrants a bug report:

   https://d.puremagic.com/issues/

Ali



More information about the Digitalmars-d-learn mailing list