From bfafb32b0ba23cd14535fd2cd28e5e4cae11be33 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 4 Nov 2014 15:29:08 +0100 Subject: [PATCH] More information for type expectation errors. --- libsolidity/AST.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 536f04cbd..e654dd575 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -347,9 +347,11 @@ void ExpressionStatement::checkTypeRequirements() void Expression::expectType(Type const& _expectedType) { checkTypeRequirements(); - if (!getType()->isImplicitlyConvertibleTo(_expectedType)) - BOOST_THROW_EXCEPTION(createTypeError("Type not implicitly convertible to expected type.")); - //@todo provide more information to the exception + const Type& type = *getType(); + if (!type.isImplicitlyConvertibleTo(_expectedType)) + BOOST_THROW_EXCEPTION(createTypeError("Type " + type.toString() + + " not implicitly convertible to expected type " + + _expectedType.toString() + ".")); } void UnaryOperation::checkTypeRequirements() @@ -373,14 +375,18 @@ void BinaryOperation::checkTypeRequirements() else if (m_left->getType()->isImplicitlyConvertibleTo(*m_right->getType())) m_commonType = m_right->getType(); else - BOOST_THROW_EXCEPTION(createTypeError("No common type found in binary operation.")); + BOOST_THROW_EXCEPTION(createTypeError("No common type found in binary operation: " + + m_left->getType()->toString() + " vs. " + + m_right->getType()->toString())); if (Token::isCompareOp(m_operator)) m_type = make_shared(); else { m_type = m_commonType; if (!m_commonType->acceptsBinaryOperator(m_operator)) - BOOST_THROW_EXCEPTION(createTypeError("Operator not compatible with type.")); + BOOST_THROW_EXCEPTION(createTypeError("Operator " + string(Token::toString(m_operator)) + + " not compatible with type " + + m_commonType->toString())); } }