diff options
author | Lu Guanqun <guanqun.lu@gmail.com> | 2015-03-06 13:02:35 +0800 |
---|---|---|
committer | Lu Guanqun <guanqun.lu@gmail.com> | 2015-03-08 22:50:54 +0800 |
commit | 40336154641da903f5721c3f2a3d136971236ed3 (patch) | |
tree | c6ecb37a98c2ef8fcfe30c3dd01112b6262c5812 /AST.cpp | |
parent | ddcfd441f304e02203f9fbed2477d69d3e48328f (diff) | |
download | dexon-solidity-40336154641da903f5721c3f2a3d136971236ed3.tar.gz dexon-solidity-40336154641da903f5721c3f2a3d136971236ed3.tar.zst dexon-solidity-40336154641da903f5721c3f2a3d136971236ed3.zip |
make it work for var x = f;
Diffstat (limited to 'AST.cpp')
-rw-r--r-- | AST.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -674,15 +674,23 @@ void FunctionCall::checkTypeRequirements() else if (OverloadedFunctionType const* overloadedTypes = dynamic_cast<OverloadedFunctionType const*>(expressionType)) { // this only applies to "x(3)" where x is assigned by "var x = f;" where f is an overloaded functions. - overloadedTypes->m_identifier->overloadResolution(*this); - FunctionType const* functionType = dynamic_cast<FunctionType const*>(overloadedTypes->m_identifier->getType().get()); + auto identifier = dynamic_cast<Identifier*>(m_expression.get()); + solAssert(identifier, "only applies to 'var x = f;'"); + + Declaration const* function = overloadedTypes->getIdentifier()->overloadResolution(*this); + if (!function) + BOOST_THROW_EXCEPTION(createTypeError("Can't resolve declarations")); + + identifier->setReferencedDeclaration(*function); + identifier->checkTypeRequirements(); + + TypePointer type = identifier->getType(); + FunctionType const* functionType = dynamic_cast<FunctionType const*>(type.get()); - // @todo actually the return type should be an anonymous struct, - // but we change it to the type of the first return value until we have structs if (functionType->getReturnParameterTypes().empty()) m_type = make_shared<VoidType>(); else - m_type = functionType->getReturnParameterTypes().front(); + m_type = functionType->getReturnParameterTypes().front(); } else BOOST_THROW_EXCEPTION(createTypeError("Type is not callable.")); @@ -781,7 +789,7 @@ void Identifier::checkTypeRequirementsWithFunctionCall(FunctionCall const& _func solAssert(m_referencedDeclaration || !m_overloadedDeclarations.empty(), "Identifier not resolved."); if (!m_referencedDeclaration) - overloadResolution(_functionCall); + setReferencedDeclaration(*overloadResolution(_functionCall)); checkTypeRequirements(); } @@ -791,7 +799,7 @@ void Identifier::checkTypeRequirementsFromVariableDeclaration() solAssert(m_referencedDeclaration || !m_overloadedDeclarations.empty(), "Identifier not resolved."); if (!m_referencedDeclaration) - m_type = make_shared<OverloadedFunctionType>(m_overloadedDeclarations, this); + m_type = make_shared<OverloadedFunctionType>(this); else checkTypeRequirements(); @@ -808,13 +816,11 @@ void Identifier::checkTypeRequirements() BOOST_THROW_EXCEPTION(createTypeError("Declaration referenced before type could be determined.")); } -void Identifier::overloadResolution(FunctionCall const& _functionCall) +Declaration const* Identifier::overloadResolution(FunctionCall const& _functionCall) { solAssert(m_overloadedDeclarations.size() > 1, "FunctionIdentifier not resolved."); solAssert(!m_referencedDeclaration, "Referenced declaration should be null before overload resolution."); - bool resolved = false; - std::vector<ASTPointer<Expression const>> arguments = _functionCall.getArguments(); std::vector<ASTPointer<ASTString>> const& argumentNames = _functionCall.getNames(); @@ -844,7 +850,7 @@ void Identifier::overloadResolution(FunctionCall const& _functionCall) { return declaration->getScope() == possibles.front()->getScope(); })) - setReferencedDeclaration(*possibles.front()); + return possibles.front(); else BOOST_THROW_EXCEPTION(createTypeError("Can't resolve identifier")); } @@ -852,6 +858,7 @@ void Identifier::overloadResolution(FunctionCall const& _functionCall) // named arguments // TODO: don't support right now BOOST_THROW_EXCEPTION(createTypeError("Named arguments with overloaded functions are not supported yet.")); + return nullptr; } void ElementaryTypeNameExpression::checkTypeRequirements() |