diff options
author | liana <liana@ethdev.com> | 2015-01-24 00:36:12 +0800 |
---|---|---|
committer | liana <liana@ethdev.com> | 2015-01-24 00:45:37 +0800 |
commit | 5de93e6acb81b9a39c1e8f1772dde81d5131e7e3 (patch) | |
tree | aec395a0f6011b1216c0ccc2f2a91e2e5d4bbc33 /Types.cpp | |
parent | 376c6182ad813384af43bdf198c4afd596699750 (diff) | |
download | dexon-solidity-5de93e6acb81b9a39c1e8f1772dde81d5131e7e3.tar.gz dexon-solidity-5de93e6acb81b9a39c1e8f1772dde81d5131e7e3.tar.zst dexon-solidity-5de93e6acb81b9a39c1e8f1772dde81d5131e7e3.zip |
- added conversion for string/hash of equal sizes
- added tests
Diffstat (limited to 'Types.cpp')
-rw-r--r-- | Types.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -140,6 +140,11 @@ bool IntegerType::isImplicitlyConvertibleTo(Type const& _convertTo) const bool IntegerType::isExplicitlyConvertibleTo(Type const& _convertTo) const { + if (_convertTo.getCategory() == Category::STRING) + { + StaticStringType const& convertTo = dynamic_cast<StaticStringType const&>(_convertTo); + return isHash() && (m_bits == convertTo.getNumBytes() * 8); + } return _convertTo.getCategory() == getCategory() || _convertTo.getCategory() == Category::CONTRACT; } @@ -367,6 +372,17 @@ bool StaticStringType::isImplicitlyConvertibleTo(Type const& _convertTo) const return convertTo.m_bytes >= m_bytes; } +bool StaticStringType::isExplicitlyConvertibleTo(Type const& _convertTo) const +{ + if (_convertTo.getCategory() == Category::INTEGER) + { + IntegerType const& convertTo = dynamic_cast<IntegerType const&>(_convertTo); + if (convertTo.isHash() && (m_bytes * 8 == convertTo.getNumBits())) + return true; + } + return isImplicitlyConvertibleTo(_convertTo); +} + bool StaticStringType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) |