www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - static init of associative array of enums not working.. why?

reply =?UTF-8?B?w5hpdmluZA==?= <oivind.loe gmail.com> writes:
Shouldn't this work? According to "Static Initialization of AAs" 
on this page, it should: https://dlang.org/spec/hash-map.html


enum DevicePropDataType {
   dString,
   dDateTime
}

enum DevicePropValType {
   property,
   miscDate
}

immutable DevicePropDataType[DevicePropValType] propDType =
   [
    DevicePropValType.property:          
DevicePropDataType.dString,
    DevicePropValType.miscDate:          
DevicePropDataType.dDateTime
    ];

void main() {
	
}

I get the following error:
/d847/f751.d(12): Error: non-constant expression 
[cast(DevicePropValType)0:cast(DevicePropDataType)0, 
cast(DevicePropValType)1:cast(DevicePropDataType)1]
Feb 26 2016
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 27 February 2016 at 04:15:06 UTC, Øivind wrote:
 Shouldn't this work? According to "Static Initialization of 
 AAs" on this page, it should: 
 https://dlang.org/spec/hash-map.html
It just isn't implemented in the compiler. Instead, you can declare it outside and set it in a static module constructor: immutable DevicePropDataType[DevicePropValType] propDType; shared static this() { propDType = [ DevicePropValType.property: DevicePropDataType.dString, DevicePropValType.miscDate: DevicePropDataType.dDateTime ]; } void main() { }
Feb 26 2016
parent reply =?UTF-8?B?w5hpdmluZA==?= <oivind.loe gmail.com> writes:
On Saturday, 27 February 2016 at 04:35:41 UTC, Adam D. Ruppe 
wrote:
 It just isn't implemented in the compiler. Instead, you can 
 declare it outside and set it in a static module constructor:
That was quick! Thank you. Should I file a ticket for this?
Feb 26 2016
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 27 February 2016 at 04:37:24 UTC, Øivind wrote:
 Should I file a ticket for this?
It is already known, just nobody has fixed it yet (and probably won't for a long time still)
Feb 26 2016