digitalmars.D.learn - non-constant expression ["foo":5, "bar":10, "baz":2000]
- Paolo Invernizzi (20/20) Nov 26 2016 This is stated in documentation [1]:
- Adam D. Ruppe (5/6) Nov 26 2016 What's the link?
- Paolo Invernizzi (6/12) Nov 27 2016 Sorry, I forgot to past it in the previous post: here it is.
- John Colvin (5/25) Nov 27 2016 Known bug.
- Paolo Invernizzi (8/38) Nov 28 2016 Thank Joan,
- Era Scarecrow (4/7) Nov 28 2016 Wasn't someone working on a Associative Array static type that
- HuskyNator (3/10) Jan 06 2022 I'm guessing there isn't.
- bauss (13/25) Jan 06 2022 While not the exact same, there's a small work around here that
- HuskyNator (4/16) Jan 06 2022 Thanks a lot!
- bauss (4/21) Jan 06 2022 The reason why it needs to be shared is because it's only
- Stefan Koch (4/16) Jan 06 2022 Actually I did a DMD patch for that some time ago.
- Tejas (7/24) Jan 06 2022 I feel like this should be done, if only for the sake of
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
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
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:Sorry, I forgot to past it in the previous post: here it is. https://dlang.org/spec/hash-map.html#static_initialization -- PaoloThis 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 27 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? --- /PaoloKnown bug. If you need a workaround, initialising the variable at load-time with `static this` should help in some cases.
Nov 27 2016
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: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... -- PaoloThis 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? --- /PaoloKnown bug. If you need a workaround, initialising the variable at load-time with `static this` should help in some cases.
Nov 28 2016
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
On Monday, 28 November 2016 at 14:41:44 UTC, Era Scarecrow wrote:On Monday, 28 November 2016 at 09:06:34 UTC, Paolo Invernizzi wrote:I'm guessing there isn't. Sadly still running into issues because of this :(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?
Jan 06 2022
On Thursday, 6 January 2022 at 12:04:12 UTC, HuskyNator wrote:On Monday, 28 November 2016 at 14:41:44 UTC, Era Scarecrow wrote:While not the exact same, there's a small work around here that can help in some cases: ```d immutable long[string] aa; shared static this() { aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; } ```On Monday, 28 November 2016 at 09:06:34 UTC, Paolo Invernizzi wrote:I'm guessing there isn't. Sadly still running into issues because of this :(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?
Jan 06 2022
On Thursday, 6 January 2022 at 13:33:24 UTC, bauss wrote:While not the exact same, there's a small work around here that can help in some cases: ```d immutable long[string] aa; shared static this() { aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; } ```Thanks a lot! I've tried it with static this() earlier, but the shared part fixes it for me.
Jan 06 2022
On Thursday, 6 January 2022 at 16:01:40 UTC, HuskyNator wrote:On Thursday, 6 January 2022 at 13:33:24 UTC, bauss wrote:The reason why it needs to be shared is because it's only executed once, where as just static this is executed for each thread.While not the exact same, there's a small work around here that can help in some cases: ```d immutable long[string] aa; shared static this() { aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; } ```Thanks a lot! I've tried it with static this() earlier, but the shared part fixes it for me.
Jan 06 2022
On Thursday, 6 January 2022 at 12:04:12 UTC, HuskyNator wrote:On Monday, 28 November 2016 at 14:41:44 UTC, Era Scarecrow wrote:Actually I did a DMD patch for that some time ago. It's here: https://github.com/dlang/dmd/pull/13087 If there is interest in this I might revive it.On Monday, 28 November 2016 at 09:06:34 UTC, Paolo Invernizzi wrote:I'm guessing there isn't. Sadly still running into issues because of this :(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?
Jan 06 2022
On Thursday, 6 January 2022 at 16:01:09 UTC, Stefan Koch wrote:On Thursday, 6 January 2022 at 12:04:12 UTC, HuskyNator wrote:I feel like this should be done, if only for the sake of consistency We can add an idiom about how initializing large AAs can lead to binary bloat, so use the `shared static this(){}` workaround instead Would you please revise it? I'll take your side on this.On Monday, 28 November 2016 at 14:41:44 UTC, Era Scarecrow wrote:Actually I did a DMD patch for that some time ago. It's here: https://github.com/dlang/dmd/pull/13087 If there is interest in this I might revive it.On Monday, 28 November 2016 at 09:06:34 UTC, Paolo Invernizzi wrote:I'm guessing there isn't. Sadly still running into issues because of this :(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?
Jan 06 2022