aboutsummaryrefslogtreecommitdiffstats
path: root/Types.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-01-27 20:53:13 +0800
committerchriseth <c@ethdev.com>2015-01-27 20:53:13 +0800
commit18fc2ed2d6a58b0064f6c1d2430ffe988f68b7ca (patch)
treed83c226c64315d5994190b61fc93c0a74fbd809d /Types.cpp
parent8dbdaa79e37619fc79b7111b12d5385f140fd1a1 (diff)
parentcad3d87482464017870080c54e3392bc5503ab20 (diff)
downloaddexon-solidity-18fc2ed2d6a58b0064f6c1d2430ffe988f68b7ca.tar.gz
dexon-solidity-18fc2ed2d6a58b0064f6c1d2430ffe988f68b7ca.tar.zst
dexon-solidity-18fc2ed2d6a58b0064f6c1d2430ffe988f68b7ca.zip
Merge pull request #857 from LianaHus/StringToHash
conversion for string to/from hash
Diffstat (limited to 'Types.cpp')
-rw-r--r--Types.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/Types.cpp b/Types.cpp
index c75cecfa..dad3a145 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -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())