+= on associative arrays leads to surprising result

ag0aep6g anonymous at example.com
Tue Aug 27 16:37:23 UTC 2019


On 27.08.19 18:12, berni wrote:
>> import std.stdio;
>>
>> void main()
>> {
>>     real[int] a;
>>     a[0] += 100;
>>     writeln(a);
>> }
> 
> results (independed of the used compiler) in
> 
>> [0:100]
> 
> I was a little bit surprised, because a[0] += 100 should be the same as 
> a[0] = a[0]+100, which leads to a range violation error. Furthermore, as 
> we work with real, I'd expected the result to be NaN...
> 
> Is this a bug? I ask, because it would be quite convenient to use it the 
> way it works now.

For what it's worth, it's in Bugzilla:
https://issues.dlang.org/show_bug.cgi?id=4463


More information about the Digitalmars-d-learn mailing list