Warn if using var x = 0

This commit is contained in:
chriseth 2017-06-22 16:08:59 +02:00
parent 73fbaa5a3e
commit 9f19bc8cbc

View File

@ -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