mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Return a type error when an enum has more than 256 members
This commit is contained in:
@@ -54,3 +54,7 @@ New Restrictions
|
||||
* The global functions ``log0``, ``log1``, ``log2``, ``log3`` and ``log4`` have been removed.
|
||||
|
||||
These are low-level functions that were largely unused. Their behaviour can be accessed from inline assembly.
|
||||
|
||||
* ``enum`` definitions cannot contain more than 256 members.
|
||||
|
||||
This will make it safe to assume that the underlying type in the ABI is always ``uint8``.
|
||||
|
||||
+5
-4
@@ -109,14 +109,15 @@ them.
|
||||
+-------------------------------+-----------------------------------------------------------------------------+
|
||||
|:ref:`contract<contracts>` |``address`` |
|
||||
+-------------------------------+-----------------------------------------------------------------------------+
|
||||
|:ref:`enum<enums>` |smallest ``uint`` type that is large enough to hold all values |
|
||||
| | |
|
||||
| |For example, an ``enum`` of 256 values or less is mapped to ``uint8`` and |
|
||||
| |an ``enum`` of 256 values is mapped to ``uint16``. |
|
||||
|:ref:`enum<enums>` |``uint8`` |
|
||||
+-------------------------------+-----------------------------------------------------------------------------+
|
||||
|:ref:`struct<structs>` |``tuple`` |
|
||||
+-------------------------------+-----------------------------------------------------------------------------+
|
||||
|
||||
.. warning::
|
||||
Before version ``0.8.0`` enums could have more than 256 members and were represented by the
|
||||
smallest integer type just big enough to hold the value of any member.
|
||||
|
||||
Design Criteria for the Encoding
|
||||
================================
|
||||
|
||||
|
||||
@@ -565,6 +565,7 @@ to and from all integer types but implicit conversion is not allowed. The expli
|
||||
from integer checks at runtime that the value lies inside the range of the enum and causes a
|
||||
:ref:`Panic error<assert-and-require>` otherwise.
|
||||
Enums require at least one member, and its default value when declared is the first member.
|
||||
Enums cannot have more than 256 members.
|
||||
|
||||
The data representation is the same as for enums in C: The options are represented by
|
||||
subsequent unsigned integer values starting from ``0``.
|
||||
@@ -586,9 +587,7 @@ subsequent unsigned integer values starting from ``0``.
|
||||
|
||||
// Since enum types are not part of the ABI, the signature of "getChoice"
|
||||
// will automatically be changed to "getChoice() returns (uint8)"
|
||||
// for all matters external to Solidity. The integer type used is just
|
||||
// large enough to hold all enum values, i.e. if you have more than 256 values,
|
||||
// `uint16` will be used and so on.
|
||||
// for all matters external to Solidity.
|
||||
function getChoice() public view returns (ActionChoices) {
|
||||
return choice;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user