mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2152 from ethereum/warnRevert
Warn about side-effect free statements.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user