[Issue 4463] [AA] double.init in associative array seems 0.0
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 22 18:09:24 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=4463
Stanislav Blinov <stanislav.blinov at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |stanislav.blinov at gmail.com
--- Comment #4 from Stanislav Blinov <stanislav.blinov at gmail.com> ---
Now that we have an .update() for AAs, this needs to be resolved. This test
should pass:
unittest {
double[int] aa;
aa[0]++;
import std.math;
assert(aa[0].isNaN);
}
The appropriate create/modify for non-zero-initialized types is:
unittest {
double[int] aa;
aa.update(0, { return 0.0; }, (ref double d) { d++; return d; });
assert(aa[0] == 1.0);
}
Let's not let convenience defeat the type system, please.
--
More information about the Digitalmars-d-bugs
mailing list