From 229587672f38a3dc54e776795c9d3ab30884940b Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Tue, 7 Apr 2020 21:11:03 +0530 Subject: [PATCH 1/2] TypeChecker error when encoding functions with call options; tests --- libsolidity/ast/Types.cpp | 2 ++ .../specialFunctions/functionCallOptions_err.sol | 11 +++++++++++ ...s_with_unspecified_encoding_internal_functions.sol | 7 +++---- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 test/libsolidity/syntaxTests/specialFunctions/functionCallOptions_err.sol diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 3fc649caf..2238e86f3 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -3112,6 +3112,8 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const* _sco TypePointer FunctionType::encodingType() const { + if (m_gasSet || m_valueSet) + return nullptr; // Only external functions can be encoded, internal functions cannot leave code boundaries. if (m_kind == Kind::External) return this; diff --git a/test/libsolidity/syntaxTests/specialFunctions/functionCallOptions_err.sol b/test/libsolidity/syntaxTests/specialFunctions/functionCallOptions_err.sol new file mode 100644 index 000000000..5ad8c4e5f --- /dev/null +++ b/test/libsolidity/syntaxTests/specialFunctions/functionCallOptions_err.sol @@ -0,0 +1,11 @@ +contract C { + function f() public payable { + abi.encode(this.f{value: 2}); + abi.encode(this.f{gas: 2}); + abi.encode(this.f{value: 2, gas: 1}); + } +} +// ---- +// TypeError: (60-76): This type cannot be encoded. +// TypeError: (92-106): This type cannot be encoded. +// TypeError: (122-146): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol index ea11703f9..eac453939 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol @@ -1,12 +1,11 @@ contract C { function f() public pure { - bytes32 h = keccak256(abi.encodePacked(keccak256, f, this.f.gas, blockhash)); + bytes32 h = keccak256(abi.encodePacked(keccak256, f, this.f{gas: 2}, blockhash)); h; } } // ---- -// Warning: (105-115): Using ".gas(...)" is deprecated. Use "{gas: ...}" instead. // TypeError: (91-100): This type cannot be encoded. // TypeError: (102-103): This type cannot be encoded. -// TypeError: (105-115): This type cannot be encoded. -// TypeError: (117-126): This type cannot be encoded. +// TypeError: (105-119): This type cannot be encoded. +// TypeError: (121-130): This type cannot be encoded. From 96411711ef32f05628c5449e242e025fe0b3b4f2 Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Tue, 7 Apr 2020 21:17:35 +0530 Subject: [PATCH 2/2] Added changelog --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 828d86ed4..bae50e7d8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ Compiler Features: Bugfixes: * SMTChecker: Fix internal error in the CHC engine when calling inherited functions internally. + * Type Checker: Error when trying to encode functions with call options gas and value.