aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorErik Kundt <bitshift@posteo.org>2018-12-05 21:34:27 +0800
committerErik Kundt <bitshift@posteo.org>2018-12-07 18:55:53 +0800
commitb2afb8cdda84f7e98fbee652c130bff0d9d30023 (patch)
treed297dd858f37da0e2fb7c4c70545c1d7ed205335 /libsolidity
parent52ff3c945531f1e6ca490475174688f496e78008 (diff)
downloaddexon-solidity-b2afb8cdda84f7e98fbee652c130bff0d9d30023.tar.gz
dexon-solidity-b2afb8cdda84f7e98fbee652c130bff0d9d30023.tar.zst
dexon-solidity-b2afb8cdda84f7e98fbee652c130bff0d9d30023.zip
Adds an additional message to failing type conversions.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp6
-rw-r--r--libsolidity/ast/Types.cpp11
2 files changed, 8 insertions, 9 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 5c8e0c6c..1c9f1956 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -1252,7 +1252,8 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
{
TypePointer const& leftType = type(_operation.leftExpression());
TypePointer const& rightType = type(_operation.rightExpression());
- TypePointer commonType = leftType->binaryOperatorResult(_operation.getOperator(), rightType);
+ TypeResult result = leftType->binaryOperatorResult(_operation.getOperator(), rightType);
+ TypePointer commonType = result.get();
if (!commonType)
{
m_errorReporter.typeError(
@@ -1262,7 +1263,8 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
" not compatible with types " +
leftType->toString() +
" and " +
- rightType->toString()
+ rightType->toString() +
+ (!result.message().empty() ? ". " + result.message() : "")
);
commonType = leftType;
}
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index fd8839ca..0822fb4a 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -512,9 +512,8 @@ TypeResult AddressType::unaryOperatorResult(Token _operator) const
TypeResult AddressType::binaryOperatorResult(Token _operator, TypePointer const& _other) const
{
- // Addresses can only be compared.
if (!TokenTraits::isCompareOp(_operator))
- return TypePointer();
+ return TypeResult{"Addresses can only be compared"};
return Type::commonType(shared_from_this(), _other);
}
@@ -678,9 +677,8 @@ TypeResult IntegerType::binaryOperatorResult(Token _operator, TypePointer const&
return TypePointer();
if (auto intType = dynamic_pointer_cast<IntegerType const>(commonType))
{
- // Signed EXP is not allowed
if (Token::Exp == _operator && intType->isSigned())
- return TypePointer();
+ return TypeResult{"Signed exponentiation is not allowed"};
}
else if (auto fixType = dynamic_pointer_cast<FixedPointType const>(commonType))
if (Token::Exp == _operator)
@@ -1128,9 +1126,8 @@ TypeResult RationalNumberType::binaryOperatorResult(Token _operator, TypePointer
uint32_t absExp = bigint(abs(exp)).convert_to<uint32_t>();
- // Limit size to 4096 bits
if (!fitsPrecisionExp(abs(m_value.numerator()), absExp) || !fitsPrecisionExp(abs(m_value.denominator()), absExp))
- return TypePointer();
+ return TypeResult{"Precision is limited to 4096 bits"};
static auto const optimizedPow = [](bigint const& _base, uint32_t _exponent) -> bigint {
if (_base == 1)
@@ -1211,7 +1208,7 @@ TypeResult RationalNumberType::binaryOperatorResult(Token _operator, TypePointer
// verify that numerator and denominator fit into 4096 bit after every operation
if (value.numerator() != 0 && max(mostSignificantBit(abs(value.numerator())), mostSignificantBit(abs(value.denominator()))) > 4096)
- return TypePointer();
+ return TypeResult{"Precision is limited to 4096 bits"};
return TypeResult(make_shared<RationalNumberType>(value));
}