mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2528 from ethereum/warnNoStorage
Warn if local storage reference variable does not use "storage" explicitly.
This commit is contained in:
@@ -289,7 +289,20 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
|
||||
typeLoc = DataLocation::Memory;
|
||||
}
|
||||
else if (varLoc == Location::Default)
|
||||
typeLoc = _variable.isCallableParameter() ? DataLocation::Memory : DataLocation::Storage;
|
||||
{
|
||||
if (_variable.isCallableParameter())
|
||||
typeLoc = DataLocation::Memory;
|
||||
else
|
||||
{
|
||||
typeLoc = DataLocation::Storage;
|
||||
if (!_variable.isStateVariable())
|
||||
m_errorReporter.warning(
|
||||
_variable.location(),
|
||||
"Variable is declared as a storage pointer. "
|
||||
"Use an explicit \"storage\" keyword to silence this warning."
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
typeLoc = varLoc == Location::Memory ? DataLocation::Memory : DataLocation::Storage;
|
||||
isPointer = !_variable.isStateVariable();
|
||||
|
||||
@@ -854,10 +854,12 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
|
||||
if (auto ref = dynamic_cast<ReferenceType const*>(type(varDecl).get()))
|
||||
{
|
||||
if (ref->dataStoredIn(DataLocation::Storage))
|
||||
m_errorReporter.warning(
|
||||
varDecl.location(),
|
||||
"Uninitialized storage pointer. Did you mean '<type> memory " + varDecl.name() + "'?"
|
||||
);
|
||||
{
|
||||
string errorText{"Uninitialized storage pointer."};
|
||||
if (varDecl.referenceLocation() == VariableDeclaration::Location::Default)
|
||||
errorText += " Did you mean '<type> memory " + varDecl.name() + "'?";
|
||||
m_errorReporter.warning(varDecl.location(), errorText);
|
||||
}
|
||||
}
|
||||
else if (dynamic_cast<MappingType const*>(type(varDecl).get()))
|
||||
m_errorReporter.typeError(
|
||||
|
||||
Reference in New Issue
Block a user