Merge pull request #2152 from ethereum/warnRevert

Warn about side-effect free statements.
This commit is contained in:
chriseth
2017-04-24 19:25:45 +02:00
committed by GitHub
5 changed files with 76 additions and 17 deletions
+7
View File
@@ -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)
+2
View File
@@ -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;
+2 -2
View File
@@ -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;
}