www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - non-constant expression ["foo":5, "bar":10, "baz":2000]

reply Paolo Invernizzi <paolo.invernizzi no.address> writes:
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
Nov 26 2016
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 26 November 2016 at 17:37:57 UTC, Paolo Invernizzi 
wrote:
 This is stated in documentation [1]:
What's the link? This is a known limitation, it has never worked. The docs should reflect that, though some day, it might start working.
Nov 26 2016
parent Paolo Invernizzi <paolo.invernizzi no.address> writes:
On Saturday, 26 November 2016 at 19:57:21 UTC, Adam D. Ruppe 
wrote:
 On Saturday, 26 November 2016 at 17:37:57 UTC, Paolo Invernizzi 
 wrote:
 This is stated in documentation [1]:
What's the link? This is a known limitation, it has never worked. The docs should reflect that, though some day, it might start working.
Sorry, I forgot to past it in the previous post: here it is. https://dlang.org/spec/hash-map.html#static_initialization -- Paolo
Nov 27 2016
prev sibling parent reply John Colvin <john.loughran.colvin gmail.com> writes:
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.
Nov 27 2016
parent reply Paolo Invernizzi <paolo.invernizzi no.address> writes:
On Sunday, 27 November 2016 at 22:25:51 UTC, John Colvin wrote:
 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.
Thank Joan, The point is that I was trying to avoid some cycle between modules, detected by 2.072. This bug leads to pollution in the use of static this only to workaround the limitation... -- Paolo
Nov 28 2016
parent Era Scarecrow <rtcvb32 yahoo.com> writes:
On Monday, 28 November 2016 at 09:06:34 UTC, Paolo Invernizzi 
wrote:
 The point is that I was trying to avoid some cycle between 
 modules, detected by 2.072. This bug leads to pollution in the 
 use of static this only to workaround the limitation...
Wasn't someone working on a Associative Array static type that could be created at CTFE and run at runtime?
Nov 28 2016