diff options
author | chriseth <chris@ethereum.org> | 2017-06-22 22:08:59 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-06-28 17:41:03 +0800 |
commit | 9f19bc8cbca127309fd8057e20d2facc22529fc0 (patch) | |
tree | 74d496aa20eaace1723fb8f10ac6cadd44b1b994 /libsolidity/analysis | |
parent | 73fbaa5a3e31d54a6456642223814fa4c044bad1 (diff) | |
download | dexon-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/analysis')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 24 |
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 |