Associative array literal is non-constant?
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Feb 3 22:46:41 PST 2012
On Fri, Feb 03, 2012 at 10:18:18PM -0800, H. S. Teoh wrote:
> Why does the following code give a compiler error?
>
> static int[string] table = ["abc":1, "def":2, "ghi":3];
>
> Error message is:
>
> prog.d:3: Error: non-constant expression ["abc":1,"def":2,"ghi":3]
>
> How is a literal non-constant?
[...]
Ugh. Just found this:
http://d.puremagic.com/issues/show_bug.cgi?id=6238
Further testing shows that assoc array literals can't be used outside of
function scope at all, for example:
// (in package scope)
auto hash = [ "abc":1, "def":2, "ghi":3 ];
// Error: non-constant expression ["abc":1,"def":2,"ghi":3]
Seems like a pretty nasty bug to me.
T
--
If the comments and the code disagree, it's likely that *both* are wrong. -- Christopher
More information about the Digitalmars-d-learn
mailing list