diff options
author | chriseth <chris@ethereum.org> | 2017-07-06 01:38:00 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-07-06 01:38:00 +0800 |
commit | dd34277ca60fcd9803a6fbb5a5944a1ed2533c73 (patch) | |
tree | a4fbb8c9dd17d03178d68b666d39ccae9a6474d9 /libsolidity/analysis | |
parent | 05a26fc98c1201057c618c536ca0537e456c9b15 (diff) | |
download | dexon-solidity-dd34277ca60fcd9803a6fbb5a5944a1ed2533c73.tar.gz dexon-solidity-dd34277ca60fcd9803a6fbb5a5944a1ed2533c73.tar.zst dexon-solidity-dd34277ca60fcd9803a6fbb5a5944a1ed2533c73.zip |
Warn if local storage reference variable does not use "storage" explicitly.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/ReferencesResolver.cpp | 15 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 10 |
2 files changed, 20 insertions, 5 deletions
diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index 2a5f27df..cc95c294 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -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(); diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 1563467c..7306a36d 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -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( |