Do not report on overriding function and only warn for view.

This commit is contained in:
chriseth 2017-08-29 17:08:08 +02:00
parent 342367d5dc
commit ec27e569b0

View File

@ -131,29 +131,36 @@ void ViewPureChecker::endVisit(InlineAssembly const& _inlineAssembly)
reportMutability(StateMutability::NonPayable, _inlineAssembly); reportMutability(StateMutability::NonPayable, _inlineAssembly);
} }
void ViewPureChecker::reportMutability(StateMutability _mutability, const ASTNode& _node) void ViewPureChecker::reportMutability(StateMutability _mutability, ASTNode const& _node)
{ {
if (m_currentFunction && m_currentFunction->stateMutability() < _mutability) if (m_currentFunction && m_currentFunction->stateMutability() < _mutability)
{ {
m_errors = true; string text;
if (_mutability == StateMutability::View) if (_mutability == StateMutability::View)
m_errorReporter.typeError( text =
_node.location(), "Function declared as pure, but this expression reads from the "
"Function declared as pure, but this expression reads from the environment or state and thus " "environment or state and thus requires \"view\".";
"requires \"view\"."
);
else if (_mutability == StateMutability::NonPayable) else if (_mutability == StateMutability::NonPayable)
m_errorReporter.typeError( text =
_node.location(),
"Function declared as " + "Function declared as " +
stateMutabilityToString(m_currentFunction->stateMutability()) + stateMutabilityToString(m_currentFunction->stateMutability()) +
", but this expression modifies the state and thus " ", but this expression modifies the state and thus "
"requires non-payable (the default) or payable." "requires non-payable (the default) or payable.";
); else
solAssert(false, "");
if (m_currentFunction->stateMutability() == StateMutability::View)
// Change this to error with 0.5.0
m_errorReporter.warning(_node.location(), text);
else if (m_currentFunction->stateMutability() == StateMutability::Pure)
{
m_errors = true;
m_errorReporter.typeError(_node.location(), text);
}
else else
solAssert(false, ""); solAssert(false, "");
} }
if (_mutability >= m_currentBestMutability) if (_mutability > m_currentBestMutability)
m_currentBestMutability = _mutability; m_currentBestMutability = _mutability;
} }