aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-06-22 22:08:59 +0800
committerchriseth <chris@ethereum.org>2017-06-28 17:41:03 +0800
commit9f19bc8cbca127309fd8057e20d2facc22529fc0 (patch)
tree74d496aa20eaace1723fb8f10ac6cadd44b1b994 /libsolidity
parent73fbaa5a3e31d54a6456642223814fa4c044bad1 (diff)
downloaddexon-solidity-9f19bc8cbca127309fd8057e20d2facc22529fc0.tar
dexon-solidity-9f19bc8cbca127309fd8057e20d2facc22529fc0.tar.gz
dexon-solidity-9f19bc8cbca127309fd8057e20d2facc22529fc0.tar.bz2
dexon-solidity-9f19bc8cbca127309fd8057e20d2facc22529fc0.tar.lz
dexon-solidity-9f19bc8cbca127309fd8057e20d2facc22529fc0.tar.xz
dexon-solidity-9f19bc8cbca127309fd8057e20d2facc22529fc0.tar.zst
dexon-solidity-9f19bc8cbca127309fd8057e20d2facc22529fc0.zip
Warn if using var x = 0
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index ef8a9345..1c91a2b0 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -956,6 +956,30 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
var.location(),
"Cannot declare variable with void (empty tuple) type."
);
+ else if (valueComponentType->category() == Type::Category::RationalNumber)
+ {
+ string typeName = var.annotation().type->toString(true);
+ string extension;
+ if (auto type = dynamic_cast<IntegerType const*>(var.annotation().type.get()))
+ {
+ int numBits = type->numBits();
+ bool isSigned = type->isSigned();
+ if (isSigned)
+ numBits--;
+ extension = ", which can hold values up to " + string((u256(1) << numBits) - 1);
+ }
+ else
+ solAssert(dynamic_cast<FixedPointType const*>(var.annotation().type.get()), "Unknown type.");
+
+ m_errorReporter.warning(
+ _statement.location(),
+ "The type of this variable was inferred as " +
+ typeName +
+ extension +
+ ". This is probably not desired. Use an explicit type to silence this warning."
+ );
+ }
+
var.accept(*this);
}
else