diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index cdbfb4e9a..0c56cb7a7 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -110,14 +110,9 @@ void FunctionDefinition::checkTypeRequirements() m_body->checkTypeRequirements(); } -std::string FunctionDefinition::getCanonicalSignature() +string FunctionDefinition::getCanonicalSignature() const { - auto parameters = getParameters(); - std::string ret = getName() + "("; - - for (auto it = parameters.cbegin(); it != parameters.cend(); ++it) - ret += (*it)->getType()->toString() + (it + 1 == parameters.end() ? "" : ","); - return ret + ")"; + return getName() + FunctionType(*this).getCanonicalSignature(); } void Block::checkTypeRequirements() diff --git a/libsolidity/AST.h b/libsolidity/AST.h index 32cc23a5b..8493d4323 100644 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -277,11 +277,10 @@ public: /// Checks that all parameters have allowed types and calls checkTypeRequirements on the body. void checkTypeRequirements(); - /// Returns the canonical signature of the function - /// That consists of the name of the function followed by the - /// types of the arguments separated by commas all enclosed in parentheses - /// without any spaces - std::string getCanonicalSignature(); + /// @returns the canonical signature of the function + /// That consists of the name of the function followed by the types of the + /// arguments separated by commas all enclosed in parentheses without any spaces. + std::string getCanonicalSignature() const; private: bool m_isPublic; diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 640a34ca8..7a4c45c6f 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -452,13 +452,12 @@ unsigned FunctionType::getSizeOnStack() const } } -std::string FunctionType::getCanonicalSignature() const +string FunctionType::getCanonicalSignature() const { - auto parameters = getParameterTypes(); - std::string ret = "NAME("; //TODO: how to get function name from FunctionType + string ret = "("; - for (auto it = parameters.cbegin(); it != parameters.cend(); ++it) - ret += (*it)->toString() + (it + 1 == m_parameterTypes.end() ? "" : ","); + for (auto it = m_parameterTypes.cbegin(); it != m_parameterTypes.cend(); ++it) + ret += (*it)->toString() + (it + 1 == m_parameterTypes.cend() ? "" : ","); return ret + ")"; } diff --git a/test/SolidityNameAndTypeResolution.cpp b/test/SolidityNameAndTypeResolution.cpp index e44c9fa29..94271b1f7 100644 --- a/test/SolidityNameAndTypeResolution.cpp +++ b/test/SolidityNameAndTypeResolution.cpp @@ -336,7 +336,24 @@ BOOST_AUTO_TEST_CASE(function_canonical_signature) if (ContractDefinition* contract = dynamic_cast(node.get())) { auto functions = contract->getDefinedFunctions(); - BOOST_ASSERT("foo(uint256,uint64,bool)" == functions[0]->getCanonicalSignature()); + BOOST_CHECK_EQUAL("foo(uint256,uint64,bool)", functions[0]->getCanonicalSignature()); + } +} + +BOOST_AUTO_TEST_CASE(function_canonical_signature_type_aliases) +{ + ASTPointer sourceUnit; + char const* text = "contract Test {\n" + " function boo(uint arg1, hash arg2, address arg3) returns (uint ret) {\n" + " ret = 5;\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(sourceUnit = parseTextAndResolveNames(text)); + for (ASTPointer const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast(node.get())) + { + auto functions = contract->getDefinedFunctions(); + BOOST_CHECK_EQUAL("boo(uint256,hash256,address)", functions[0]->getCanonicalSignature()); } }