diff options
author | Christian <c@ethdev.com> | 2015-02-27 21:50:06 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-02-28 05:52:19 +0800 |
commit | 2ea8f3a75a9eaf6006052426168cb70ef5c6fa8d (patch) | |
tree | c65235ecd2b8b17786c674db6c1621656f979fb8 /Types.cpp | |
parent | 87365f7612336c4c7f443aac568f8a515bc9bd35 (diff) | |
download | dexon-solidity-2ea8f3a75a9eaf6006052426168cb70ef5c6fa8d.tar.gz dexon-solidity-2ea8f3a75a9eaf6006052426168cb70ef5c6fa8d.tar.zst dexon-solidity-2ea8f3a75a9eaf6006052426168cb70ef5c6fa8d.zip |
Type checks for array assignment.
Diffstat (limited to 'Types.cpp')
-rw-r--r-- | Types.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -537,7 +537,19 @@ TypePointer ContractType::unaryOperatorResult(Token::Value _operator) const bool ArrayType::isImplicitlyConvertibleTo(const Type& _convertTo) const { - return _convertTo.getCategory() == getCategory(); + if (_convertTo.getCategory() != getCategory()) + return false; + auto& convertTo = dynamic_cast<ArrayType const&>(_convertTo); + // let us not allow assignment to memory arrays for now + if (convertTo.getLocation() != Location::Storage) + return false; + if (convertTo.isByteArray() != isByteArray()) + return false; + if (!getBaseType()->isImplicitlyConvertibleTo(*convertTo.getBaseType())) + return false; + if (convertTo.isDynamicallySized()) + return true; + return !isDynamicallySized() && convertTo.getLength() >= getLength(); } TypePointer ArrayType::unaryOperatorResult(Token::Value _operator) const @@ -552,7 +564,10 @@ bool ArrayType::operator==(Type const& _other) const if (_other.getCategory() != getCategory()) return false; ArrayType const& other = dynamic_cast<ArrayType const&>(_other); - return other.m_location == m_location; + if (other.m_location != m_location || other.isByteArray() != isByteArray() || + other.isDynamicallySized() != isDynamicallySized()) + return false; + return isDynamicallySized() || getLength() == other.getLength(); } u256 ArrayType::getStorageSize() const |