diff options
author | chriseth <chris@ethereum.org> | 2018-08-14 23:29:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-14 23:29:16 +0800 |
commit | 34d3000dcc20cbcf0e0eb71c71fb43403a9db9d8 (patch) | |
tree | 9d809a3843d4715b021469daca829a5da19ff648 /docs | |
parent | 0e3cbea6f2a5d020bfbb973eda9587eec5a1626b (diff) | |
parent | c05911914550388d7a28563096e3b9772f1b9d23 (diff) | |
download | dexon-solidity-34d3000dcc20cbcf0e0eb71c71fb43403a9db9d8.tar dexon-solidity-34d3000dcc20cbcf0e0eb71c71fb43403a9db9d8.tar.gz dexon-solidity-34d3000dcc20cbcf0e0eb71c71fb43403a9db9d8.tar.bz2 dexon-solidity-34d3000dcc20cbcf0e0eb71c71fb43403a9db9d8.tar.lz dexon-solidity-34d3000dcc20cbcf0e0eb71c71fb43403a9db9d8.tar.xz dexon-solidity-34d3000dcc20cbcf0e0eb71c71fb43403a9db9d8.tar.zst dexon-solidity-34d3000dcc20cbcf0e0eb71c71fb43403a9db9d8.zip |
Merge pull request #4372 from JesseBusman/implicit-convertibility-functions
Add implicit convertibility to function pointer with higher state mutability
Diffstat (limited to 'docs')
-rw-r--r-- | docs/types.rst | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/docs/types.rst b/docs/types.rst index 78451b39..18400dee 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -430,8 +430,26 @@ function type should not return anything, the whole ``returns (<return types>)`` part has to be omitted. By default, function types are internal, so the ``internal`` keyword can be -omitted. In contrast, contract functions themselves are public by default, -only when used as the name of a type, the default is internal. +omitted. Note that this only applies to function types. Visibility has +to be specified explicitly for functions defined in contracts, they +do not have a default. + +A function type ``A`` is implicitly convertible to a function type ``B`` if and only if +their parameter types are identical, their return types are identical, +their internal/external property is identical and the state mutability of ``A`` +is not more restrictive than the state mutability of ``B``. In particular: + + - ``pure`` functions can be converted to ``view`` and ``non-payable`` functions + - ``view`` functions can be converted to ``non-payable`` functions + - ``payable`` functions can be converted to ``non-payable`` functions + +No other conversions are possible. + +The rule about ``payable`` and ``non-payable`` might be a little +confusing, but in essence, if a function is ``payable``, this means that it +also accepts a payment of zero Ether, so it also is ``non-payable``. +On the other hand, a ``non-payable`` function will reject Ether sent to it, +so ``non-payable`` functions cannot be converted to ``payable`` functions. If a function type variable is not initialized, calling it will result in an exception. The same happens if you call a function after using ``delete`` |