Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? `shared_AA.saa` should still be instance variable, not class variable, right?

Nick Treleaven nick at geany.org
Tue Jun 25 21:13:44 UTC 2024


On Tuesday, 25 June 2024 at 02:16:25 UTC, mw wrote:
> Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? (and of 
> course print out the same contents).
>
> `shared_AA.saa` should still be instance variable, not class 
> variable, right?

`saa` is an instance variable, but both `foo.x.saa` and 
`foo.y.saa` are initialized to the same instance of 
`shared_AA_class`. I think in the next edition of D we can forbid 
tail mutable initializers.

BTW there's also another issue that the initializer is not TLS - 
that could probably be fixed (also in an edition) to use TLS.

https://forum.dlang.org/post/sexmkjnbtxvsvodcacjq@forum.dlang.org


More information about the Digitalmars-d-learn mailing list