From 94a49fcc4aa470b815ba0d85f20ea5f3def2d6ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 9 Oct 2020 15:42:28 +0200 Subject: [PATCH 1/2] Additional tests for ABIEncoderV1 calls using ABIEncoderV2 types --- ...sing_public_state_variable_via_v1_type.sol | 15 +++++++++++++ ...sing_public_state_variable_via_v2_type.sol | 17 ++++++++++++++ ...ibrary_bound_function_returning_struct.sol | 22 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 test/libsolidity/syntaxTests/abiEncoder/v1_accessing_public_state_variable_via_v1_type.sol create mode 100644 test/libsolidity/syntaxTests/abiEncoder/v1_accessing_public_state_variable_via_v2_type.sol create mode 100644 test/libsolidity/syntaxTests/abiEncoder/v1_call_to_v2_library_bound_function_returning_struct.sol diff --git a/test/libsolidity/syntaxTests/abiEncoder/v1_accessing_public_state_variable_via_v1_type.sol b/test/libsolidity/syntaxTests/abiEncoder/v1_accessing_public_state_variable_via_v1_type.sol new file mode 100644 index 000000000..e88775901 --- /dev/null +++ b/test/libsolidity/syntaxTests/abiEncoder/v1_accessing_public_state_variable_via_v1_type.sol @@ -0,0 +1,15 @@ +struct Item { + uint x; + uint y; +} + +contract D { + Item[][][] public items; + + function test() public view returns (uint) { + // The autogenerated getters to not use ABI encoder. + (uint a, uint b) = this.items(1, 2, 3); + return a + b; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/abiEncoder/v1_accessing_public_state_variable_via_v2_type.sol b/test/libsolidity/syntaxTests/abiEncoder/v1_accessing_public_state_variable_via_v2_type.sol new file mode 100644 index 000000000..326101a37 --- /dev/null +++ b/test/libsolidity/syntaxTests/abiEncoder/v1_accessing_public_state_variable_via_v2_type.sol @@ -0,0 +1,17 @@ +struct Item { + uint x; + uint y; +} + +contract D { + Item[][][] public items; + + function test() public view returns (uint) { + // The autogenerated getters to not use ABI encoder. + Item memory item = this.items(1, 2, 3); + return item.x + item.y; + } +} +// ---- +// TypeError 7364: (202-240): Different number of components on the left hand side (1) than on the right hand side (2). +// TypeError 9574: (202-240): Type uint256 is not implicitly convertible to expected type struct Item memory. diff --git a/test/libsolidity/syntaxTests/abiEncoder/v1_call_to_v2_library_bound_function_returning_struct.sol b/test/libsolidity/syntaxTests/abiEncoder/v1_call_to_v2_library_bound_function_returning_struct.sol new file mode 100644 index 000000000..eeaa6ac58 --- /dev/null +++ b/test/libsolidity/syntaxTests/abiEncoder/v1_call_to_v2_library_bound_function_returning_struct.sol @@ -0,0 +1,22 @@ +==== Source: A ==== +pragma experimental ABIEncoderV2; + +library L { + struct Item { + uint x; + } + + function f(uint) external view returns (Item memory) {} +} +==== Source: B ==== +import "A"; + +contract D { + using L for uint; + + function test() public { + uint(1).f(); + } +} +// ---- +// TypeError 2428: (B:86-97): The type of return parameter 1, struct L.Item, is only supported in ABIEncoderV2. Use "pragma experimental ABIEncoderV2;" to enable the feature. From 692e4487ba7747b48f557bed8ba146ebf5057fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 9 Oct 2020 17:56:54 +0200 Subject: [PATCH 2/2] Expand docs on mixed ABIEncoderV2 and V1 use --- docs/layout-of-source-files.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/layout-of-source-files.rst b/docs/layout-of-source-files.rst index afc6ce221..ea14c8330 100644 --- a/docs/layout-of-source-files.rst +++ b/docs/layout-of-source-files.rst @@ -111,6 +111,14 @@ activate it using ``pragma experimental ABIEncoderV2;`` - we kept the same pragma, even though it is not considered experimental anymore. +The set of types supported by the new encoder is a strict superset of +the ones supported by the old one. Contracts that use it can interact with ones +that do not without limitations. The reverse is possible only as long as the +non-``ABIEncoderV2`` contract does not try to make calls that would require +decoding types only supported by the new encoder. The compiler can detect this +and will issue an error. Simply enabling ``ABIEncoderV2`` for your contract is +enough to make the error go away. + .. _smt_checker: SMTChecker