diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-09 00:43:38 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-09 00:43:38 +0800 |
commit | a7b661d3be53b4c6a05401782ab8f90202a4f776 (patch) | |
tree | a2fdb25e88821def4962e1eacf303ec8f89cdfc3 /AST.cpp | |
parent | 184ddca5a108c5f3d026aa372a2af2f63b2694f9 (diff) | |
parent | d18fa27b6a48540298e835ad324152566586c65c (diff) | |
download | dexon-solidity-a7b661d3be53b4c6a05401782ab8f90202a4f776.tar.gz dexon-solidity-a7b661d3be53b4c6a05401782ab8f90202a4f776.tar.zst dexon-solidity-a7b661d3be53b4c6a05401782ab8f90202a4f776.zip |
merging develop
Diffstat (limited to 'AST.cpp')
-rw-r--r-- | AST.cpp | 35 |
1 files changed, 15 insertions, 20 deletions
@@ -185,12 +185,18 @@ void Assignment::checkTypeRequirements() //@todo later, assignments to structs might be possible, but not to mappings if (!m_leftHandSide->getType()->isValueType() && !m_leftHandSide->isLocalLValue()) BOOST_THROW_EXCEPTION(createTypeError("Assignment to non-local non-value lvalue.")); - m_rightHandSide->expectType(*m_leftHandSide->getType()); m_type = m_leftHandSide->getType(); - if (m_assigmentOperator != Token::ASSIGN) + if (m_assigmentOperator == Token::ASSIGN) + m_rightHandSide->expectType(*m_type); + else + { // compound assignment - if (!m_type->acceptsBinaryOperator(Token::AssignmentToBinaryOp(m_assigmentOperator))) + m_rightHandSide->checkTypeRequirements(); + TypePointer resultType = Type::binaryOperatorResult(Token::AssignmentToBinaryOp(m_assigmentOperator), + m_type, m_rightHandSide->getType()); + if (!resultType || *resultType != *m_type) BOOST_THROW_EXCEPTION(createTypeError("Operator not compatible with type.")); + } } void ExpressionStatement::checkTypeRequirements() @@ -230,24 +236,13 @@ void BinaryOperation::checkTypeRequirements() { m_left->checkTypeRequirements(); m_right->checkTypeRequirements(); - if (m_right->getType()->isImplicitlyConvertibleTo(*m_left->getType())) - m_commonType = m_left->getType(); - 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: " + - m_left->getType()->toString() + " vs. " + + m_commonType = Type::binaryOperatorResult(m_operator, m_left->getType(), m_right->getType()); + if (!m_commonType) + BOOST_THROW_EXCEPTION(createTypeError("Operator " + string(Token::toString(m_operator)) + + " not compatible with types " + + m_left->getType()->toString() + " and " + 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 " + string(Token::toString(m_operator)) + - " not compatible with type " + - m_commonType->toString())); - } + m_type = Token::isCompareOp(m_operator) ? make_shared<BoolType>() : m_commonType; } void FunctionCall::checkTypeRequirements() |