digitalmars.D - static immutable AAs documentation
- =?UTF-8?B?THXDrXM=?= Marques (18/18) Dec 14 2017 The documentation for AAs gives out this example
- Jonathan M Davis (11/29) Dec 14 2017 It should probably just be changed to used a shared static constructor. ...
The documentation for AAs gives out this example (<https://dlang.org/spec/hash-map.html#static_initialization>): immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; unittest { assert(aa["foo"] == 5); assert(aa["bar"] == 10); assert(aa["baz"] == 2000); } This isn't actually supported: <https://issues.dlang.org/show_bug.cgi?id=6238> <https://issues.dlang.org/show_bug.cgi?id=1578> Given how long this limitation has persisted, wouldn't it be best to remove that section from the documentation?
Dec 14 2017
On Friday, December 15, 2017 03:49:53 Luís Marques via Digitalmars-d wrote:The documentation for AAs gives out this example (<https://dlang.org/spec/hash-map.html#static_initialization>): immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; unittest { assert(aa["foo"] == 5); assert(aa["bar"] == 10); assert(aa["baz"] == 2000); } This isn't actually supported: <https://issues.dlang.org/show_bug.cgi?id=6238> <https://issues.dlang.org/show_bug.cgi?id=1578> Given how long this limitation has persisted, wouldn't it be best to remove that section from the documentation?It should probably just be changed to used a shared static constructor. e.g. immutable long[string] aa; shared static this() { aa = ["foo": 5, "bar": 10, "baz": 2000]; } since that does work. - Jonathan M Davis
Dec 14 2017