Allow constants of any value type

I am interested in declaring an array data type and declaring it as a constant.

However, I get the compiler error: “Only constants of value type and byte array type are implemented”.



uint[7] public myArray = [400, 250, 135, 110, 55, 25, 20];

Not valid:

uint[7] public constant myArray = [400, 250, 135, 110, 55, 25, 20];

I understand that this may seem pedantic to want to have in Solidity, however, I want to be absolutely sure that this array is immutable. Currently this is not possible.


Not pedantic at all, this is a true necessity.

But it’s a pending request since probably around the time solc was first released (I personally recall asking about this as early as mid 2017).

Oh well, there you go - a github issue from March 2017 (seems that somebody has asked for this feature even before I did).