On Monday, January 29, 2018 09:23:55 Sobaya via Digitalmars-d-learn wrote: > I found a strange behavior. > > class A { > void opAssign(int v) {} > } > > class Test { > A a; > this() { > a = new A(); // removing this causes compile error. > a = 3; // cannot implicitly convert expression `3` of > `int` to `A` > } > } > > void main() { > // this is allowed. > A a; > a = 3; > } > > Is it a compiiler's bug?
I don't think so. The first "assignment" is actually initialization, not assignment. opAssign is for assigning to a value that was already initialized. - Jonathan M Davis