non-constant expression ["foo":5, "bar":10, "baz":2000]

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 27 14:25:51 PST 2016


On Saturday, 26 November 2016 at 17:37:57 UTC, Paolo Invernizzi 
wrote:
> This is stated in documentation [1]:
>
> immutable long[string] aa = [
>   "foo": 5,
>   "bar": 10,
>   "baz": 2000
> ];
>
> unittest
> {
>     assert(aa["foo"] == 5);
>     assert(aa["bar"] == 10);
>     assert(aa["baz"] == 2000);
> }
>
> But results to:
>
>    Error: non-constant expression ["foo":5L, "bar":10L, 
> "baz":2000L]
>
> Known bug?
> If yes, Is there the need to emend the documentation, till the 
> bug is open?
> ---
> /Paolo

Known bug.

If you need a workaround, initialising the variable at load-time 
with `static this` should help in some cases.


More information about the Digitalmars-d-learn mailing list