mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow exponentials with signed base and unsigned power.
This commit is contained in:
@@ -1397,6 +1397,23 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
|
||||
"might overflow. Silence this warning by converting the literal to the "
|
||||
"expected type."
|
||||
);
|
||||
if (
|
||||
commonType->category() == Type::Category::Integer &&
|
||||
rightType->category() == Type::Category::Integer &&
|
||||
dynamic_cast<IntegerType const&>(*commonType).numBits() <
|
||||
dynamic_cast<IntegerType const&>(*rightType).numBits()
|
||||
)
|
||||
m_errorReporter.warning(
|
||||
_operation.location(),
|
||||
"The result type of the " +
|
||||
operation +
|
||||
" operation is equal to the type of the first operand (" +
|
||||
commonType->toString() +
|
||||
") ignoring the (larger) type of the second operand (" +
|
||||
rightType->toString() +
|
||||
") which might be unexpected. Silence this warning by either converting "
|
||||
"the first or the second operand to the type of the other."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -600,6 +600,17 @@ TypeResult IntegerType::binaryOperatorResult(Token _operator, Type const* _other
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
else if (Token::Exp == _operator)
|
||||
{
|
||||
if (auto otherIntType = dynamic_cast<IntegerType const*>(_other))
|
||||
{
|
||||
if (otherIntType->isSigned())
|
||||
return TypeResult::err("Exponentiation power is not allowed to be a signed integer type.");
|
||||
}
|
||||
else if (dynamic_cast<FixedPointType const*>(_other))
|
||||
return nullptr;
|
||||
return this;
|
||||
}
|
||||
|
||||
auto commonType = Type::commonType(this, _other); //might be an integer or fixed point
|
||||
if (!commonType)
|
||||
@@ -610,14 +621,6 @@ TypeResult IntegerType::binaryOperatorResult(Token _operator, Type const* _other
|
||||
return commonType;
|
||||
if (TokenTraits::isBooleanOp(_operator))
|
||||
return nullptr;
|
||||
if (auto intType = dynamic_cast<IntegerType const*>(commonType))
|
||||
{
|
||||
if (Token::Exp == _operator && intType->isSigned())
|
||||
return TypeResult::err("Exponentiation is not allowed for signed integer types.");
|
||||
}
|
||||
else if (dynamic_cast<FixedPointType const*>(commonType))
|
||||
if (Token::Exp == _operator)
|
||||
return nullptr;
|
||||
return commonType;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user