aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2017-03-11 02:25:47 +0800
committerGitHub <noreply@github.com>2017-03-11 02:25:47 +0800
commitef8b56a05823e39ffc2577af653200f22d6b15a1 (patch)
tree507b8c8194e503b073bd3cf82de058b27f08b486 /libsolidity/analysis
parentf1dd79c7433a6c78e879a0b597b0585921838f1e (diff)
parent1324ebc4bf84438715744afb9bcf1469b8e00b05 (diff)
downloaddexon-solidity-ef8b56a05823e39ffc2577af653200f22d6b15a1.tar.gz
dexon-solidity-ef8b56a05823e39ffc2577af653200f22d6b15a1.tar.zst
dexon-solidity-ef8b56a05823e39ffc2577af653200f22d6b15a1.zip
Merge pull request #1751 from ethereum/warnLiteralExpBase
Warn if base of exponentiation operation is a literal.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 549cbcca..fbff6865 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -1105,6 +1105,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)