Disallow explicit conversions from negative literals to `address`

This commit is contained in:
Harikrishnan Mulackal
2020-10-07 16:06:02 +02:00
committed by hrkrshnn
parent b401093679
commit a309669f75
9 changed files with 61 additions and 14 deletions
+10 -6
View File
@@ -963,13 +963,17 @@ BoolResult RationalNumberType::isExplicitlyConvertibleTo(Type const& _convertTo)
{
if (isImplicitlyConvertibleTo(_convertTo))
return true;
else if (_convertTo.category() != Category::FixedBytes)
{
TypePointer mobType = mobileType();
return (mobType && mobType->isExplicitlyConvertibleTo(_convertTo));
}
else
auto category = _convertTo.category();
if (category == Category::FixedBytes)
return false;
if (category == Category::Address)
if (isNegative() || isFractional() || integerType()->numBits() > 160)
return false;
TypePointer mobType = mobileType();
return (mobType && mobType->isExplicitlyConvertibleTo(_convertTo));
}
TypeResult RationalNumberType::unaryOperatorResult(Token _operator) const