aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-04-21 17:13:10 +0800
committerchriseth <chris@ethereum.org>2017-04-21 17:36:38 +0800
commit9bc9fe6af7241479fe3099eae235452b054a6f11 (patch)
tree78cfc115c1c71b9bb59b55bc8bb99d25711bbd81 /libsolidity
parented64c849f57b9aeed1eda4563f0d4340013420ef (diff)
downloaddexon-solidity-9bc9fe6af7241479fe3099eae235452b054a6f11.tar.gz
dexon-solidity-9bc9fe6af7241479fe3099eae235452b054a6f11.tar.zst
dexon-solidity-9bc9fe6af7241479fe3099eae235452b054a6f11.zip
Warn about side-effect free statements.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/StaticAnalyzer.cpp7
-rw-r--r--libsolidity/analysis/StaticAnalyzer.h2
-rw-r--r--libsolidity/analysis/TypeChecker.cpp4
3 files changed, 11 insertions, 2 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp
index c39f874e..df7f6e88 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 effects.");
+ 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;
}