Stupid question about AA. The following code works but I don't undrstand why?!

Uranuz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 9 12:31:31 PDT 2016


On Saturday, 9 April 2016 at 19:25:32 UTC, Uranuz wrote:
> On Saturday, 9 April 2016 at 18:27:11 UTC, ag0aep6g wrote:
>> [...]
>
> Another observation is illustrated with the foloving code:
> http://dpaste.dzfl.pl/8d68fd5922b7
>
> Because AA and arrays are not created before they were assigned 
> some value it leads to inconsistency in behavior. And will 
> produce unexpected and hidden bugs that is not good. It's not 
> very good side of D's array and AA. But classes could be also 
> affected by this *feature* (or bug, as you wish). So we must 
> always construct reference semantics types before passing them 
> to functions that will modify it. For classes it's obvious but 
> for AA and dynamic arrays is not.
>
> Another solution is to pass reference types by *ref*. So you 
> will not have such bugs in implementation

I think that we need to add warning about such case in 
documentation section:
https://dlang.org/spec/hash-map.html#construction_and_ref_semantic

in order to prevent this kind of mistakes in code.


More information about the Digitalmars-d-learn mailing list