bug in doc?
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Mar 14 14:52:15 UTC 2019
On Thu, Mar 14, 2019 at 03:22:52PM +0100, spir via Digitalmars-d-learn wrote:
> https://dlang.org/spec/hash-map.html#static_initialization:
>
> immutable long[string] aa = [
> "foo": 5,
> "bar": 10,
> "baz": 2000
> ];
>
> ==> Error: non-constant expression `["foo":5L, "bar":10L, "baz":2000L]`
>
> Also: I don't understand the error message:
> * What is non-constant in the *expression*?
> * And why should it be constant at all?
> (Removing "immutable" does not help...)
[...]
It's a well-known limitation. The workaround is:
immutable long[string] aa;
static this() {
aa = [
"foo" : 5,
...
];
}
T
--
Trying to define yourself is like trying to bite your own teeth. -- Alan Watts
More information about the Digitalmars-d-learn
mailing list