Browse Source

More information for type expectation errors.

cl-refactor
Christian 10 years ago
parent
commit
bfafb32b0b
  1. 16
      libsolidity/AST.cpp

16
libsolidity/AST.cpp

@ -347,9 +347,11 @@ void ExpressionStatement::checkTypeRequirements()
void Expression::expectType(Type const& _expectedType) void Expression::expectType(Type const& _expectedType)
{ {
checkTypeRequirements(); checkTypeRequirements();
if (!getType()->isImplicitlyConvertibleTo(_expectedType)) const Type& type = *getType();
BOOST_THROW_EXCEPTION(createTypeError("Type not implicitly convertible to expected type.")); if (!type.isImplicitlyConvertibleTo(_expectedType))
//@todo provide more information to the exception BOOST_THROW_EXCEPTION(createTypeError("Type " + type.toString() +
" not implicitly convertible to expected type "
+ _expectedType.toString() + "."));
} }
void UnaryOperation::checkTypeRequirements() void UnaryOperation::checkTypeRequirements()
@ -373,14 +375,18 @@ void BinaryOperation::checkTypeRequirements()
else if (m_left->getType()->isImplicitlyConvertibleTo(*m_right->getType())) else if (m_left->getType()->isImplicitlyConvertibleTo(*m_right->getType()))
m_commonType = m_right->getType(); m_commonType = m_right->getType();
else 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)) if (Token::isCompareOp(m_operator))
m_type = make_shared<BoolType>(); m_type = make_shared<BoolType>();
else else
{ {
m_type = m_commonType; m_type = m_commonType;
if (!m_commonType->acceptsBinaryOperator(m_operator)) 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()));
} }
} }

Loading…
Cancel
Save