diff options
author | chriseth <c@ethdev.com> | 2017-03-07 20:44:11 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2017-03-07 20:44:11 +0800 |
commit | 1324ebc4bf84438715744afb9bcf1469b8e00b05 (patch) | |
tree | cab32c7ec215aaae04620545b6b400d376a121c7 /libsolidity/analysis | |
parent | 774cdb1135dfe3f0ed8646c72326874c63bce645 (diff) | |
download | dexon-solidity-1324ebc4bf84438715744afb9bcf1469b8e00b05.tar.gz dexon-solidity-1324ebc4bf84438715744afb9bcf1469b8e00b05.tar.zst dexon-solidity-1324ebc4bf84438715744afb9bcf1469b8e00b05.zip |
Warn about literal constant base in exponentiation.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 5426cd17..88078d3d 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1092,6 +1092,26 @@ void TypeChecker::endVisit(BinaryOperation const& _operation) Token::isCompareOp(_operation.getOperator()) ? make_shared<BoolType>() : commonType; + if (_operation.getOperator() == Token::Exp) + { + if ( + leftType->category() == Type::Category::RationalNumber && + rightType->category() != Type::Category::RationalNumber + ) + if (( + commonType->category() == Type::Category::Integer && + dynamic_cast<IntegerType const&>(*commonType).numBits() != 256 + ) || ( + commonType->category() == Type::Category::FixedPoint && + dynamic_cast<FixedPointType const&>(*commonType).numBits() != 256 + )) + warning( + _operation.location(), + "Result of exponentiation has type " + commonType->toString() + " and thus " + "might overflow. Silence this warning by converting the literal to the " + "expected type." + ); + } } bool TypeChecker::visit(FunctionCall const& _functionCall) |