From 82cb5338a90b13a6d9483164bdb7734ed021c86a Mon Sep 17 00:00:00 2001 From: Nikola Matic Date: Tue, 18 Jul 2023 13:55:46 +0200 Subject: [PATCH] Relax delegatecall type restriction plus test --- libsolidity/ast/Types.cpp | 8 +++----- .../functionTypes/declaration_type_conversion.sol | 3 ++- .../ternary_contract_delegate_function.sol | 12 ++++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 test/libsolidity/syntaxTests/functionTypes/ternary_contract_delegate_function.sol diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 47e1fea04..2b955369f 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -3423,12 +3423,10 @@ MemberList::MemberMap FunctionType::nativeMembers(ASTNode const* _scope) const } case Kind::DelegateCall: { - auto const* functionDefinition = dynamic_cast(m_declaration); - solAssert(functionDefinition, ""); - solAssert(functionDefinition->visibility() != Visibility::Private, ""); - if (functionDefinition->visibility() != Visibility::Internal) + if (auto const* functionDefinition = dynamic_cast(m_declaration)) { - auto const* contract = dynamic_cast(m_declaration->scope()); + solAssert(functionDefinition->visibility() > Visibility::Internal, ""); + auto const *contract = dynamic_cast(m_declaration->scope()); solAssert(contract, ""); solAssert(contract->isLibrary(), ""); return {{"selector", TypeProvider::fixedBytes(4)}}; diff --git a/test/libsolidity/syntaxTests/functionTypes/declaration_type_conversion.sol b/test/libsolidity/syntaxTests/functionTypes/declaration_type_conversion.sol index a26460dc1..c31c49aea 100644 --- a/test/libsolidity/syntaxTests/functionTypes/declaration_type_conversion.sol +++ b/test/libsolidity/syntaxTests/functionTypes/declaration_type_conversion.sol @@ -8,4 +8,5 @@ contract C { } } // ---- -// TypeError 1080: (117-130): True expression's type function D.f() does not match false expression's type function D.g(). +// TypeError 9717: (121-124): Invalid mobile type in true expression. +// TypeError 3703: (127-130): Invalid mobile type in false expression. diff --git a/test/libsolidity/syntaxTests/functionTypes/ternary_contract_delegate_function.sol b/test/libsolidity/syntaxTests/functionTypes/ternary_contract_delegate_function.sol new file mode 100644 index 000000000..810f5eb21 --- /dev/null +++ b/test/libsolidity/syntaxTests/functionTypes/ternary_contract_delegate_function.sol @@ -0,0 +1,12 @@ +library L { + function f() external {} +} + +contract C { + function test() public { + (true ? L.f : L.f).selector; + } +} + +// ---- +// TypeError 9582: (94-121): Member "selector" not found or not visible after argument-dependent lookup in function ().