Skip to content

Commit ec4ccf8

Browse files
minaminaoLeo Alt
authored andcommitted
Improve docs of possible function inputs and outputs
1 parent 681581d commit ec4ccf8

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

docs/contracts/functions.rst

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ with two integers, you would use something like the following:
7272
7373
Function parameters can be used as any other local variable and they can also be assigned to.
7474

75-
.. note::
76-
77-
Until version 0.6.0 it was not possible to use a multi-dimensional array or a struct
78-
as an input for an :ref:`external function<external-function-calls>`.
79-
``abicoder v2`` made it possible and it's been enabled by default since version 0.8.0
80-
(before that you had to enable it with ``pragma abicoder v2;``).
81-
82-
An :ref:`internal function<internal-function-calls>` can accept a
83-
multi-dimensional array or a struct without any restrictions.
84-
8575
.. index:: return array, return string, array, string, array of strings, dynamic array, variably sized array, return struct, struct
8676

8777
Return Variables
@@ -139,12 +129,16 @@ If you use an early ``return`` to leave a function that has return variables,
139129
you must provide return values together with the return statement.
140130

141131
.. note::
142-
You cannot return some types from non-internal functions, notably
143-
multi-dimensional dynamic arrays and structs. If you enable the
144-
ABI coder v2 by adding ``pragma abicoder v2;``
145-
to your source file then more types are available, but
146-
``mapping`` types are still limited to inside a single contract and you
147-
cannot transfer them.
132+
You cannot return some types from non-internal functions.
133+
This includes the types listed below and any composite types that recursively contain them:
134+
135+
- mappings,
136+
- internal function types,
137+
- reference types with location set to ``storage``,
138+
- multi-dimensional arrays (applies only to :ref:`ABI coder v1 <abi_coder>`),
139+
- structs (applies only to :ref:`ABI coder v1 <abi_coder>`).
140+
141+
This restriction does not apply to library functions because of their different :ref:`internal ABI <library-selectors>`.
148142

149143
.. _multi-return:
150144

docs/layout-of-source-files.rst

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ you have to add the pragma to all your files if you want to enable it
5656
in your whole project. If you :ref:`import<import>` another file, the pragma
5757
from that file does *not* automatically apply to the importing file.
5858

59-
.. index:: ! pragma, version
59+
.. index:: ! pragma;version
6060

6161
.. _version_pragma:
6262

@@ -91,19 +91,21 @@ these follow the same syntax used by `npm <https://docs.npmjs.com/cli/v6/using-n
9191
required by the pragma. If it does not match, the compiler issues
9292
an error.
9393

94+
.. index:: ! ABI coder, ! pragma; abicoder, pragma; ABIEncoderV2
95+
.. _abi_coder:
96+
9497
ABI Coder Pragma
9598
----------------
9699

97100
By using ``pragma abicoder v1`` or ``pragma abicoder v2`` you can
98101
select between the two implementations of the ABI encoder and decoder.
99102

100103
The new ABI coder (v2) is able to encode and decode arbitrarily nested
101-
arrays and structs. It might produce less optimal code and has not
102-
received as much testing as the old encoder, but is considered
103-
non-experimental as of Solidity 0.6.0. You still have to explicitly
104-
activate it using ``pragma abicoder v2;``. Since it will be
105-
activated by default starting from Solidity 0.8.0, there is the option to select
106-
the old coder using ``pragma abicoder v1;``.
104+
arrays and structs. Apart from supporting more types, it involves more extensive
105+
validation and safety checks, which may result in higher gas costs, but also heightened
106+
security. It is considered
107+
non-experimental as of Solidity 0.6.0 and it is enabled by default starting
108+
with Solidity 0.8.0. There old coder can still be selected using ``pragma abicoder v1;``.
107109

108110
The set of types supported by the new encoder is a strict superset of
109111
the ones supported by the old one. Contracts that use it can interact with ones
@@ -126,8 +128,7 @@ enough to make the error go away.
126128
by using ``pragma experimental ABIEncoderV2``, but it was not possible
127129
to explicitly select coder v1 because it was the default.
128130

129-
.. index:: ! pragma, experimental
130-
131+
.. index:: ! pragma; experimental
131132
.. _experimental_pragma:
132133

133134
Experimental Pragma
@@ -137,6 +138,7 @@ The second pragma is the experimental pragma. It can be used to enable
137138
features of the compiler or language that are not yet enabled by default.
138139
The following experimental pragmas are currently supported:
139140

141+
.. index:: ! pragma; ABIEncoderV2
140142

141143
ABIEncoderV2
142144
~~~~~~~~~~~~
@@ -145,6 +147,7 @@ Because the ABI coder v2 is not considered experimental anymore,
145147
it can be selected via ``pragma abicoder v2`` (please see above)
146148
since Solidity 0.7.4.
147149

150+
.. index:: ! pragma; SMTChecker
148151
.. _smt_checker:
149152

150153
SMTChecker

0 commit comments

Comments
 (0)