diff options
author | chriseth <chris@ethereum.org> | 2018-06-20 03:32:03 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-08-01 18:04:35 +0800 |
commit | c8232d9759458d5f6e1442533457d8529686eea7 (patch) | |
tree | cb1d8f4876b4984213134ad56ff5fb15db867d57 /libsolidity/ast | |
parent | 21888e246b771325ea55da39d7f335638da1a98e (diff) | |
download | dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar.gz dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar.bz2 dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar.lz dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar.xz dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.tar.zst dexon-solidity-c8232d9759458d5f6e1442533457d8529686eea7.zip |
Disallow conversion between unrelated contract types.
Diffstat (limited to 'libsolidity/ast')
-rw-r--r-- | libsolidity/ast/Types.cpp | 11 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 4 |
2 files changed, 7 insertions, 8 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 2c2d3b68..7b079f45 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1403,15 +1403,15 @@ bool ContractType::isImplicitlyConvertibleTo(Type const& _convertTo) const { if (*this == _convertTo) return true; - if (_convertTo.category() == Category::Integer) - return dynamic_cast<IntegerType const&>(_convertTo).isAddress(); if (_convertTo.category() == Category::Contract) { auto const& bases = contractDefinition().annotation().linearizedBaseContracts; if (m_super && bases.size() <= 1) return false; - return find(m_super ? ++bases.begin() : bases.begin(), bases.end(), - &dynamic_cast<ContractType const&>(_convertTo).contractDefinition()) != bases.end(); + return find( + m_super ? ++bases.begin() : bases.begin(), bases.end(), + &dynamic_cast<ContractType const&>(_convertTo).contractDefinition() + ) != bases.end(); } return false; } @@ -1420,8 +1420,7 @@ bool ContractType::isExplicitlyConvertibleTo(Type const& _convertTo) const { return isImplicitlyConvertibleTo(_convertTo) || - _convertTo.category() == Category::Integer || - _convertTo.category() == Category::Contract; + _convertTo == IntegerType(160, IntegerType::Modifier::Address); } bool ContractType::isPayable() const diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 1a676b42..474a6f33 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -692,9 +692,9 @@ public: virtual Category category() const override { return Category::Contract; } explicit ContractType(ContractDefinition const& _contract, bool _super = false): m_contract(_contract), m_super(_super) {} - /// Contracts can be implicitly converted to super classes and to addresses. + /// Contracts can be implicitly converted only to base contracts. virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override; - /// Contracts can be converted to themselves and to integers. + /// Contracts can only be explicitly converted to address types and base contracts. virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override; virtual TypePointer unaryOperatorResult(Token::Value _operator) const override; virtual std::string richIdentifier() const override; |