On Saturday, 18 July 2015 at 02:28:09 UTC, tcak wrote:
I even am not sure how in the world it allows implicit conversion from class to struct in "fine" at all.

Given:

struct Foo {
   T x;
   alias x this;
}


Any time you do

Foo foo;

foo.something = whatever;
// or
foo = whatever;
// or
whatever = foo;


It first tries that code directly. If that doesn't work, it then tries rewriting `foo` into `foo.x`:

foo.x.something = whatever;
foo.x = whatever;
whatever = foo.x;


And if that compiles, you're all set, that code gets generated.


The OP's situation is just case #2 here. The compiler is taking the illegal `thing = new Foo;` and rewriting it into the legal `thing.foo = new Foo;` automatically via alias this.

Reply via email to