Unify collision warnings

This commit is contained in:
a3d4
2020-09-14 02:17:53 +02:00
parent 3817515015
commit e7a6534d4f
11 changed files with 29 additions and 39 deletions
+5 -15
View File
@@ -611,25 +611,15 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
if (varType->dataStoredIn(DataLocation::Storage))
{
auto collisionMessage = [&](string const& variableOrType, bool isVariable) -> string {
return
(isVariable ? "Variable " : "Type ") +
util::escapeAndQuoteString(variableOrType) +
vector<Type const*> oversizedSubtypes = frontend::oversizedSubtypes(*varType);
for (Type const* subtype: oversizedSubtypes)
{
string message = "Type " + subtype->toString(true) +
" covers a large part of storage and thus makes collisions likely."
" Either use mappings or dynamic arrays and allow their size to be increased only"
" in small quantities per transaction.";
};
if (varType->storageSizeUpperBound() >= bigint(1) << 64)
{
if (_variable.isStateVariable())
m_errorReporter.warning(3408_error, _variable.location(), collisionMessage(_variable.name(), true));
else
m_errorReporter.warning(2332_error, _variable.typeName().location(), collisionMessage(varType->toString(true), false));
m_errorReporter.warning(7325_error, _variable.typeName().location(), message);
}
vector<Type const*> oversizedSubtypes = frontend::oversizedSubtypes(*varType);
for (Type const* subtype: oversizedSubtypes)
m_errorReporter.warning(7325_error, _variable.typeName().location(), collisionMessage(subtype->canonicalName(), false));
}
return false;
+1 -1
View File
@@ -205,7 +205,7 @@ vector<frontend::Type const*> solidity::frontend::oversizedSubtypes(frontend::Ty
{
set<StructDefinition const*> structsSeen;
TypeSet oversized;
oversizedSubtypesInner(_type, false, structsSeen, oversized);
oversizedSubtypesInner(_type, true, structsSeen, oversized);
vector<frontend::Type const*> res;
copy(oversized.cbegin(), oversized.cend(), back_inserter(res));
return res;