in not working with enum'd AA

Jonathan M Davis jmdavisProg at gmx.com
Mon Feb 27 01:11:46 PST 2012


On Monday, February 27, 2012 09:34:49 Nathan M. Swan wrote:
> I don't think this should happen:
> 
>         private enum KeywordsToTypes = [
>             "import"d    : TT.KwIMPORT,
>             "public"d    : TT.KwPUBLIC,
>             "protected"d : TT.KwPROTECTED,
>             "private"d   : TT.KwPRIVATE,
>             "static"d    : TT.KwSTATIC,
>         ];
> 
>         static this() {
>             // writes "0"
>             std.stdio.writeln("import"d in KeywordsToTypes);
>         }
> 
> Is there a reason why, or is this a bug?

No, that shouldn't happen, and I think that there's already a bug report on a 
similar issue. But I would point out that the value of an enum is effectively 
copy-pasted wherever it is used, so you're going to end up with a new instance 
of the AA everywhere that you use it. So, having an enum which is an AA is a 
_bad_ idea. It would be far better to use immutable.

- Jonathan M Davis


More information about the Digitalmars-d mailing list