Thread overview
Re: bug in doc?
Mar 14, 2019
H. S. Teoh
Mar 14, 2019
spir
Mar 14, 2019
Dennis
March 14, 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
March 14, 2019
On 14/03/2019 15:52, H. S. Teoh via Digitalmars-d-learn wrote:
> 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,
> 			...
> 		];
> 	}

All right! No language has to be perfect... (I'm joking). But the doc (the language ref for the matter) should definitely say what you just explained above, shouldn't they? I actually think clearly stating limitations is a +++. (Like an industry company that does not make perfect product but has great client support.)
diniz

March 14, 2019
On Thursday, 14 March 2019 at 19:46:30 UTC, spir wrote:
> But the doc (the language ref for the matter) should definitely say what you just explained above, shouldn't they?

Well arguably, the spec should detail the language semantics formally and not just be a description of the reference implementation also mentioning bugs. As it's currently written however, and also considering that there's only one implementation, the doc should probably mention it.