Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 27, 2016 static init of associative array of enums not working.. why? | ||||
---|---|---|---|---|
| ||||
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] |
February 27, 2016 Re: static init of associative array of enums not working.. why? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Øivind | 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() { } |
February 27, 2016 Re: static init of associative array of enums not working.. why? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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?
|
February 27, 2016 Re: static init of associative array of enums not working.. why? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Øivind | 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)
|
Copyright © 1999-2021 by the D Language Foundation