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:
hrkrshnn
2020-11-06 19:15:02 +01:00
parent 7f1d8b9bf0
commit 03f58c6b52
7 changed files with 46 additions and 11 deletions
+3
View File
@@ -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));