diff options
Diffstat (limited to 'libsolidity')
-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 |