aboutsummaryrefslogtreecommitdiffstats
path: root/AST.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'AST.cpp')
-rw-r--r--AST.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/AST.cpp b/AST.cpp
index 44cf3929..565560ad 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -337,9 +337,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
+ Type const& type = *getType();
+ if (!type.isImplicitlyConvertibleTo(_expectedType))
+ BOOST_THROW_EXCEPTION(createTypeError("Type " + type.toString() +
+ " not implicitly convertible to expected type "
+ + _expectedType.toString() + "."));
}
void UnaryOperation::checkTypeRequirements()
@@ -363,14 +365,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<BoolType>();
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()));
}
}
@@ -479,6 +485,8 @@ void ElementaryTypeNameExpression::checkTypeRequirements()
void Literal::checkTypeRequirements()
{
m_type = Type::forLiteral(*this);
+ if (!m_type)
+ BOOST_THROW_EXCEPTION(createTypeError("Literal value too large."));
}
}