Deprecating this(this)

ag0aep6g anonymous at example.com
Tue Apr 3 11:36:27 UTC 2018


On 04/03/2018 09:39 AM, Kagamin wrote:
> On Monday, 2 April 2018 at 14:42:17 UTC, ag0aep6g wrote:
>> The way it works in a const constructor is that `this.foo = bar;` is 
>> considered initialization, not assignment.
> 
> Do you mean the spec? Andrei complained about implementation.

Andrei complained about both, no? His words: "Too many bugs in design 
and implementation." Design = spec.

I'm also talking about the implementation. `this.foo = bar;` in a 
constructor is at least not normal assignment. If foo has opAssign, that 
won't be called.

> Const constructors are already implemented as needed for postblit.

Maybe. But we can't explain the special assignment semantics with it 
being initialization.

Or can we?

For constructors, we say that the first assignment is actually 
initialization. The compiler might or might not put the .init value down 
before calling the constructor. Doesn't matter, because the constructor 
will overwrite it anyway, and nothing of value is lost.

We can do the same with the postblit function: First assignment is 
actually initialization. When the compiler sees that the postblit 
function initializes a field, it can skip that field when blitting. But 
it can also just blit the whole struct, because it doesn't matter if the 
value just gets overwritten.

In other words, a postblit function can either:

1) use the blitted value as a starting point, like a constructor can use 
the .init value, or it can
2) initialize the field itself.

Would make perfect sense to me.


More information about the Digitalmars-d mailing list