On Sunday, 14 February 2021 at 08:38:49 UTC, Boris Carvajal wrote:
On Sunday, 14 February 2021 at 07:09:20 UTC, frame wrote:
Although x is well initialized by A by calling opAssign(), the
compiler doesn't care and calls the S!T ctor() on B again and
opAssign() is ignored. Is this a bug or a rule?
It's a rule described here:
https://dlang.org/spec/struct.html#field-init
"In a constructor body ... the first instance of field
assignment is its initialization."
If you assign a second time, it will use the opAssign method.
The first instance is in A - and why opAssign then works there?