mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Strict explicit conversion between literals and enums
Explicit conversions between literals and enums are only allowed if the literal can represent a value in the enum.
This commit is contained in:
@@ -978,6 +978,9 @@ BoolResult RationalNumberType::isExplicitlyConvertibleTo(Type const& _convertTo)
|
||||
}
|
||||
else if (category == Category::Integer)
|
||||
return false;
|
||||
else if (auto enumType = dynamic_cast<EnumType const*>(&_convertTo))
|
||||
if (isNegative() || isFractional() || m_value >= enumType->numberOfMembers())
|
||||
return false;
|
||||
|
||||
TypePointer mobType = mobileType();
|
||||
return (mobType && mobType->isExplicitlyConvertibleTo(_convertTo));
|
||||
|
||||
Reference in New Issue
Block a user