diff options
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/ast/Types.cpp | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 0df68d3d..d989cb06 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -290,7 +290,8 @@ bool IntegerType::isExplicitlyConvertibleTo(Type const& _convertTo) const return _convertTo.category() == category() || _convertTo.category() == Category::Contract || _convertTo.category() == Category::Enum || - _convertTo.category() == Category::FixedBytes; + _convertTo.category() == Category::FixedBytes || + _convertTo.category() == Category::FixedPoint; } TypePointer IntegerType::unaryOperatorResult(Token::Value _operator) const @@ -328,10 +329,13 @@ string IntegerType::toString(bool) const TypePointer IntegerType::binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const { - if (_other->category() != Category::RationalNumber && _other->category() != category()) + if ( + _other->category() != Category::RationalNumber && + _other->category() != Category::FixedPoint && + _other->category() != category() + ) return TypePointer(); - auto commonType = dynamic_pointer_cast<IntegerType const>(Type::commonType(shared_from_this(), _other)); - + auto commonType = Type::commonType(shared_from_this(), _other); //might be a integer or fixed point if (!commonType) return TypePointer(); @@ -341,9 +345,14 @@ TypePointer IntegerType::binaryOperatorResult(Token::Value _operator, TypePointe if (Token::isBooleanOp(_operator)) return TypePointer(); // Nothing else can be done with addresses - if (commonType->isAddress()) - return TypePointer(); - + if (auto intType = dynamic_pointer_cast<IntegerType const>(commonType)) + { + if (intType->isAddress()) + return TypePointer(); + } + else if (auto fixType = dynamic_pointer_cast<FixedPointType const>(commonType)) + if (Token::Exp == _operator) + return TypePointer(); return commonType; } @@ -386,7 +395,6 @@ bool FixedPointType::isImplicitlyConvertibleTo(Type const& _convertTo) const else return !convertTo.isSigned() || (convertTo.m_integerBits > m_integerBits); } - return false; } @@ -432,12 +440,12 @@ string FixedPointType::toString(bool) const TypePointer FixedPointType::binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const { if ( - _other->category() != Category::RationalNumber - && _other->category() != category() - && _other->category() != Category::Integer + _other->category() != Category::RationalNumber && + _other->category() != category() && + _other->category() != Category::Integer ) return TypePointer(); - auto commonType = dynamic_pointer_cast<FixedPointType const>(Type::commonType(shared_from_this(), _other)); + auto commonType = Type::commonType(shared_from_this(), _other); //might be fixed point or integer if (!commonType) return TypePointer(); @@ -447,8 +455,14 @@ TypePointer FixedPointType::binaryOperatorResult(Token::Value _operator, TypePoi return commonType; if (Token::isBitOp(_operator) || Token::isBooleanOp(_operator)) return TypePointer(); - if (Token::Exp == _operator) - return TypePointer(); + if (auto fixType = dynamic_pointer_cast<FixedPointType const>(commonType)) + { + if (Token::Exp == _operator) + return TypePointer(); + } + else if (auto intType = dynamic_pointer_cast<IntegerType const>(commonType)) + if (intType->isAddress()) + return TypePointer(); return commonType; } |