diff options
author | chriseth <chris@ethereum.org> | 2017-04-25 01:25:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-25 01:25:45 +0800 |
commit | 4d111e3366c9ddf15a750569baeed3fccb201682 (patch) | |
tree | 1f03eaffe028016a920d3ef9f699edf1ab177d8f /libsolidity/analysis | |
parent | 0b2a05c84d83b1f22acb4201d0792d7f7865d1f9 (diff) | |
parent | 9577f87dfcd2d8b532f698c0aa1e8f9c01bb0ba5 (diff) | |
download | dexon-solidity-4d111e3366c9ddf15a750569baeed3fccb201682.tar.gz dexon-solidity-4d111e3366c9ddf15a750569baeed3fccb201682.tar.zst dexon-solidity-4d111e3366c9ddf15a750569baeed3fccb201682.zip |
Merge pull request #2152 from ethereum/warnRevert
Warn about side-effect free statements.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/StaticAnalyzer.cpp | 7 | ||||
-rw-r--r-- | libsolidity/analysis/StaticAnalyzer.h | 2 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 4 |
3 files changed, 11 insertions, 2 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index c39f874e..190d2420 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -57,6 +57,13 @@ void StaticAnalyzer::endVisit(FunctionDefinition const&) m_nonPayablePublic = false; } +bool StaticAnalyzer::visit(ExpressionStatement const& _statement) +{ + if (_statement.expression().annotation().isPure) + warning(_statement.location(), "Statement has no effect."); + return true; +} + bool StaticAnalyzer::visit(MemberAccess const& _memberAccess) { if (m_nonPayablePublic && !m_library) diff --git a/libsolidity/analysis/StaticAnalyzer.h b/libsolidity/analysis/StaticAnalyzer.h index 0cb961bd..84342322 100644 --- a/libsolidity/analysis/StaticAnalyzer.h +++ b/libsolidity/analysis/StaticAnalyzer.h @@ -60,6 +60,8 @@ private: virtual bool visit(FunctionDefinition const& _function) override; virtual void endVisit(FunctionDefinition const& _function) override; + virtual bool visit(ExpressionStatement const& _statement) override; + virtual bool visit(MemberAccess const& _memberAccess) override; ErrorList& m_errors; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index dc04404d..b37db7b7 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1674,8 +1674,8 @@ bool TypeChecker::visit(Identifier const& _identifier) if (auto variableDeclaration = dynamic_cast<VariableDeclaration const*>(annotation.referencedDeclaration)) annotation.isPure = annotation.isConstant = variableDeclaration->isConstant(); else if (dynamic_cast<MagicVariableDeclaration const*>(annotation.referencedDeclaration)) - if (auto functionType = dynamic_cast<FunctionType const*>(annotation.type.get())) - annotation.isPure = functionType->isPure(); + if (dynamic_cast<FunctionType const*>(annotation.type.get())) + annotation.isPure = true; return false; } |