Merge pull request #8023 from ethereum/updateConversionFor060

Update type conversions for 0.6.0.
This commit is contained in:
chriseth 2019-12-17 12:33:21 +01:00 committed by GitHub
commit d13438eed8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,9 +8,8 @@ Conversions between Elementary Types
Implicit Conversions
--------------------
If an operator is applied to different types, the compiler tries to implicitly
convert one of the operands to the type of the other (the same is true for assignments).
This means that operations are always performed in the type of one of the operands.
An implicit type conversion is automatically applied by the compiler in some cases
during assignments, when passing arguments to functions and when applying operators.
In general, an implicit conversion between value-types is possible if it makes
sense semantically and no information is lost.
@ -18,7 +17,27 @@ For example, ``uint8`` is convertible to
``uint16`` and ``int128`` to ``int256``, but ``int8`` is not convertible to ``uint256``,
because ``uint256`` cannot hold values such as ``-1``.
For more details, please consult the sections about the types themselves.
If an operator is applied to different types, the compiler tries to implicitly
convert one of the operands to the type of the other (the same is true for assignments).
This means that operations are always performed in the type of one of the operands.
For more details about which implicit conversions are possible,
please consult the sections about the types themselves.
In the example below, ``y`` and ``z``, the operands of the addition,
do not have the same type, but ``uint8`` can
be implicitly converted to ``uint16`` and not vice-versa. Because of that,
``y`` is converted to the type of ``z`` before the addition is performed
in the ``uint16`` type. The resulting type of the expression ``y + z`` is ``uint16`.
Because it is assigned to a variable of type ``uint32`` another implicit conversion
is performed after the addition.
::
uint8 y;
uint16 z;
uint32 x = y + z;
Explicit Conversions
--------------------