[Issue 6238] New: Cannot define global immutable AA

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 1 21:59:30 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6238

           Summary: Cannot define global immutable AA
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: johann.macdonagh at gmail.com


--- Comment #0 from Johann MacDonagh <johann.macdonagh at gmail.com> 2011-07-01 21:54:32 PDT ---
I *believe* this bug has been discussed and reported before, but a search
didn't turn up anything. This code fails to compile:

immutable test = // auto, const, etc.. also fail
[
    'a' : 1,
    'b' : 2,
];

void main()
{
}

On 2.053 we get:
main.d(2): Error: non-constant expression ['a':1,'b':2]

A workaround is to do:

enum test =
[
    'a' : 1,
    'b' : 2,
];

void main()
{
    auto localTest = test;

    // Use either test or localTest
}

But of course that will cause test to be copied each time it is referenced
(which, besides all the drama in issue 4397 I believe to be correct).

The reason this matters is because of CTFE. If I have an AA which I want to be
able to use in CTFE and at runtime without causing copies to be made at runtime
I'd have to use an immutable AA.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list