mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7743 from ethereum/fixice-7558
Disallow conversion from ``super``
This commit is contained in:
commit
d696b3c92b
@ -35,6 +35,7 @@ Bugfixes:
|
||||
* SMTChecker: Fix internal error when implicitly converting string literals to fixed bytes.
|
||||
* Type Checker: Disallow constructor of the same class to be used as modifier.
|
||||
* Type Checker: Treat magic variables as unknown identifiers in inline assembly.
|
||||
* Code Generator: Fix internal error when trying to convert ``super`` to a different type
|
||||
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -0,0 +1,15 @@
|
||||
contract S
|
||||
{
|
||||
int o;
|
||||
function foo() public returns (int) { return o = 3; }
|
||||
}
|
||||
|
||||
contract B is S
|
||||
{
|
||||
function fii() public
|
||||
{
|
||||
o = S(super).foo();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (129-137): Explicit type conversion not allowed from "contract super B" to "contract S".
|
Loading…
Reference in New Issue
Block a user