Merge pull request #10604 from ethereum/strict-address-payable

[BREAKING] Strict address payable
This commit is contained in:
chriseth
2020-12-15 18:25:31 +01:00
committed by GitHub
15 changed files with 109 additions and 45 deletions
+11 -5
View File
@@ -89,6 +89,10 @@ This section lists changes that might cause existing contracts to not compile an
- ``address(uint)`` and ``uint(address)``: converting both type-category and width. Replace this by
``address(uint160(uint))`` and ``uint(uint160(address))`` respectively.
- ``payable(uint160)``, ``payable(bytes20)`` and ``payable(integer-literal)``: converting both
type-category and state-mutability. Replace this by ``payable(address(uint160))``,
``payable(address(bytes20))`` and ``payable(address(integer-literal))`` respectively. Note that
``payable(0)`` is valid and is an exception to the rule.
- ``int80(bytes10)`` and ``bytes10(int80)``: converting both type-category and sign. Replace this by
``int80(uint80(bytes10))`` and ``bytes10(uint80(int80)`` respectively.
- ``Contract(uint)``: converting both type-category and width. Replace this by
@@ -125,11 +129,13 @@ This section lists changes that might cause existing contracts to not compile an
particular, the following explicit conversions have the type ``address`` instead of ``address
payable``:
- ``address(u)`` where ``u`` is an arbitrary variable of type ``uint160``. One can convert ``u``
into the type ``address payable`` by using an explicit conversion, i.e., ``payable(u)``.
- ``address(b)`` where ``b`` is an arbitrary variable of type ``bytes20``. One can convert ``b``
into the type ``address payable`` by using an explicit conversion, i.e., ``payable(bytes20)``.
- ``address(c)`` where ``c`` is an arbitrary contract. Previously, the return type of this
- ``address(u)`` where ``u`` is a variable of type ``uint160``. One can convert ``u``
into the type ``address payable`` by using two explicit conversions, i.e.,
``payable(address(u))``.
- ``address(b)`` where ``b`` is a variable of type ``bytes20``. One can convert ``b``
into the type ``address payable`` by using two explicit conversions, i.e.,
``payable(address(b))``.
- ``address(c)`` where ``c`` is a contract. Previously, the return type of this
conversion depended on whether the contract can receive Ether (either by having a receive
function or a payable fallback function). The conversion ``payable(c)`` has the type ``address
payable`` and is only allowed when the contract ``c`` can receive Ether. In general, one can
+7 -10
View File
@@ -188,17 +188,14 @@ Type conversions:
Implicit conversions from ``address payable`` to ``address`` are allowed, whereas conversions from ``address`` to ``address payable``
must be explicit via ``payable(<address>)``.
Explicit conversions to and from ``address`` are allowed for integers, integer literals, ``bytes20`` and contract types with the following
caveat:
The result of a conversion of the form ``address(x)``
has the type ``address payable``, if ``x`` is of integer or fixed bytes type,
or a contract with a receive or payable fallback function.
If ``x`` is a contract without a receive or payable fallback function,
then ``address(x)`` will be of type ``address``.
Similarly, if ``x`` is a literal, then ``address(x)`` will also be of type ``address``.
In external function signatures ``address`` is used for both the ``address`` and the ``address payable`` type.
Explicit conversions to and from ``address`` are allowed for ``uint160``, integer literals,
``bytes20`` and contract types.
Only expressions of type ``address`` can be converted to type ``address payable`` via ``payable(<address>)``.
Only expressions of type ``address`` and contract-type can be converted to the type ``address
payable`` via the explicit conversion ``payable(...)``. For contract-type, this conversion is only
allowed if the contract can receive Ether, i.e., the contract either has a :ref:`receive
<receive-ether-function>` or a payable fallback function. Note that ``payable(0)`` is valid and is
an exception to this rule.
.. note::
If you need a variable of type ``address`` and plan to send Ether to it, then