associative array: unexpected results after static initialization

kdevel kdevel at vogtner.de
Fri Dec 1 16:46:22 UTC 2017


On Friday, 1 December 2017 at 16:23:33 UTC, H. S. Teoh wrote:
> On Fri, Dec 01, 2017 at 04:06:50PM +0000, kdevel via 
> Digitalmars-d-learn wrote:
>> On Friday, 1 December 2017 at 00:42:00 UTC, H. S. Teoh wrote:
>> > Here's the fix:
>> > 
>> > 	https://github.com/dlang/druntime/pull/1980
>> 
>> And wouldn't it be reasonable to add
>> 
>>    assert(aa.values == [ "b" ]);
>> 
>> to the unittest?
>
> I did think about adding that, but then I didn't want the 
> unittest to dictate which value should take precedence when 
> there are duplicate keys, since that is currently 
> implementation-dependent.  At the very least, it merits further 
> discussion.

I personally would have preferred a run time or even a 
compile-time error in the case of my orginal example. That would 
support the "fail fast" philosohphy. IMHO it makes no sense at 
all to initialize an AA in such a way. The way the initialization 
works hides copy-and-paste errors like the one of my example code.


More information about the Digitalmars-d-learn mailing list