Disallow conversion from `super`

This commit is contained in:
Mathias Baumann
2019-11-19 17:14:11 +01:00
parent f6191a7183
commit 23cad71c88
4 changed files with 26 additions and 0 deletions
+7
View File
@@ -1433,6 +1433,9 @@ Type const* ContractType::encodingType() const
BoolResult ContractType::isImplicitlyConvertibleTo(Type const& _convertTo) const
{
if (m_super)
return false;
if (*this == _convertTo)
return true;
if (_convertTo.category() == Category::Contract)
@@ -1450,8 +1453,12 @@ BoolResult ContractType::isImplicitlyConvertibleTo(Type const& _convertTo) const
BoolResult ContractType::isExplicitlyConvertibleTo(Type const& _convertTo) const
{
if (m_super)
return false;
if (auto const* addressType = dynamic_cast<AddressType const*>(&_convertTo))
return isPayable() || (addressType->stateMutability() < StateMutability::Payable);
return isImplicitlyConvertibleTo(_convertTo);
}
+3
View File
@@ -711,6 +711,9 @@ void CompilerUtils::convertType(
Type::Category stackTypeCategory = _typeOnStack.category();
Type::Category targetTypeCategory = _targetType.category();
if (auto contrType = dynamic_cast<ContractType const*>(&_typeOnStack))
solAssert(!contrType->isSuper(), "Cannot convert magic variable \"super\"");
bool enumOverflowCheckPending = (targetTypeCategory == Type::Category::Enum || stackTypeCategory == Type::Category::Enum);
bool chopSignBitsPending = _chopSignBits && targetTypeCategory == Type::Category::Integer;
if (chopSignBitsPending)