mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Warn if using var x = 0
This commit is contained in:
parent
73fbaa5a3e
commit
9f19bc8cbc
@ -956,6 +956,30 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
|
|||||||
var.location(),
|
var.location(),
|
||||||
"Cannot declare variable with void (empty tuple) type."
|
"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);
|
var.accept(*this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user