non-constant error for module AA"s

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Jan 24 16:48:34 PST 2011


On 1/24/11, BlazingWhitester <max.klyga at gmail.com> wrote:
> On 2011-01-24 17:45:03 +0200, Andrej Mitrovic said:
>
>> Is this a bug?
>>
>> import std.stdio;
>>
>> string[string] values = ["abc":"abc", "def":"def"];
>>
>> void main()
>> {
>>     string[string] values2 = ["abc":"abc", "def":"def"];
>> }
>>
>>
>> test.d(3): Error: non-constant expression ["abc":"abc","def":"def"]
>>
>> What's non-constant about that expression?
>
> It's because of D's implementation of AA, but you can make it work with
> enum, e.g. enum string[string] values = ["abc":"abc", "def":"def"]; //
> works just fine at compile time
>
>

It's interesting that enum works but immutable doesn't. enum will do, Thanks.


More information about the Digitalmars-d-learn mailing list