aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2018-05-08 20:26:01 +0800
committerchriseth <chris@ethereum.org>2018-05-17 00:32:47 +0800
commit5c59d56335f3777b9e4ad595b66787ed563b26f1 (patch)
tree3099b0f30601a86f030710d8805758a31cee54b3 /libsolidity
parent76fc4f8e00a994f0d961d2ca5f0eafa500b20e8e (diff)
downloaddexon-solidity-5c59d56335f3777b9e4ad595b66787ed563b26f1.tar.gz
dexon-solidity-5c59d56335f3777b9e4ad595b66787ed563b26f1.tar.zst
dexon-solidity-5c59d56335f3777b9e4ad595b66787ed563b26f1.zip
Disallow conversions between bytesX and uintY of different size.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/ast/Types.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 066868c9..000b1063 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -476,7 +476,7 @@ bool IntegerType::isExplicitlyConvertibleTo(Type const& _convertTo) const
return _convertTo.category() == category() ||
_convertTo.category() == Category::Contract ||
_convertTo.category() == Category::Enum ||
- _convertTo.category() == Category::FixedBytes ||
+ (_convertTo.category() == Category::FixedBytes && numBits() == dynamic_cast<FixedBytesType const&>(_convertTo).numBytes() * 8) ||
_convertTo.category() == Category::FixedPoint;
}
@@ -884,7 +884,10 @@ bool RationalNumberType::isImplicitlyConvertibleTo(Type const& _convertTo) const
bool RationalNumberType::isExplicitlyConvertibleTo(Type const& _convertTo) const
{
TypePointer mobType = mobileType();
- return mobType && mobType->isExplicitlyConvertibleTo(_convertTo);
+ return
+ (mobType && mobType->isExplicitlyConvertibleTo(_convertTo)) ||
+ (!isFractional() && _convertTo.category() == Category::FixedBytes)
+ ;
}
TypePointer RationalNumberType::unaryOperatorResult(Token::Value _operator) const
@@ -1281,7 +1284,7 @@ bool FixedBytesType::isImplicitlyConvertibleTo(Type const& _convertTo) const
bool FixedBytesType::isExplicitlyConvertibleTo(Type const& _convertTo) const
{
- return _convertTo.category() == Category::Integer ||
+ return (_convertTo.category() == Category::Integer && numBytes() * 8 == dynamic_cast<IntegerType const&>(_convertTo).numBits()) ||
_convertTo.category() == Category::FixedPoint ||
_convertTo.category() == category();
}