diff options
author | chriseth <chris@ethereum.org> | 2018-11-22 22:37:26 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-11-22 22:47:45 +0800 |
commit | 92ba8a95f6f1348c2bc71eea4b550a7f33b13ec7 (patch) | |
tree | 8553d641c6545f86b158211664bd2f7d2a6c5941 | |
parent | 9e964852cc1da9a30ba9ff995f5b9c5d10ea2d4a (diff) | |
download | dexon-solidity-92ba8a95f6f1348c2bc71eea4b550a7f33b13ec7.tar.gz dexon-solidity-92ba8a95f6f1348c2bc71eea4b550a7f33b13ec7.tar.zst dexon-solidity-92ba8a95f6f1348c2bc71eea4b550a7f33b13ec7.zip |
Make asCallableFunction to never fail and assert abount parameter size if bound instead.
-rw-r--r-- | libsolidity/ast/Types.cpp | 13 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 3 |
2 files changed, 8 insertions, 8 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 95f461ec..102e43e9 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -442,10 +442,11 @@ MemberList::MemberMap Type::boundFunctions(Type const& _type, ContractDefinition if (!function->isVisibleAsLibraryMember() || seenFunctions.count(function)) continue; seenFunctions.insert(function); - FunctionType funType(*function, false); - if (auto fun = funType.asCallableFunction(true, true)) - if (_type.isImplicitlyConvertibleTo(*fun->selfType())) - members.push_back(MemberList::Member(function->name(), fun, function)); + if (function->parameters().empty()) + continue; + FunctionTypePointer fun = FunctionType(*function, false).asCallableFunction(true, true); + if (_type.isImplicitlyConvertibleTo(*fun->selfType())) + members.push_back(MemberList::Member(function->name(), fun, function)); } } return members; @@ -3061,8 +3062,8 @@ TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) con FunctionTypePointer FunctionType::asCallableFunction(bool _inLibrary, bool _bound) const { - if (_bound && m_parameterTypes.empty()) - return FunctionTypePointer(); + if (_bound) + solAssert(!m_parameterTypes.empty(), ""); TypePointers parameterTypes; for (auto const& t: m_parameterTypes) diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 3b3b2bdf..953aa557 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -1158,9 +1158,8 @@ public: /// from CallData to Memory. This is the type that would be used when the function is /// called, as opposed to the parameter types that are available inside the function body. /// Also supports variants to be used for library or bound calls. - /// Returns empty shared pointer on a failure. Namely, if a bound function has no parameters. /// @param _inLibrary if true, uses DelegateCall as location. - /// @param _bound if true, the arguments are placed as `arg1.functionName(arg2, ..., argn)`. + /// @param _bound if true, the function type is set to be bound. FunctionTypePointer asCallableFunction(bool _inLibrary, bool _bound = false) const; private: |