Remove v050 check for enforcing "view" in ViewPureChecker.

This commit is contained in:
Daniel Kirchner 2018-05-11 10:40:32 +02:00
parent 533d5d4b1c
commit 7ea8365ab0
2 changed files with 13 additions and 26 deletions

View File

@ -116,31 +116,22 @@ private:
bool ViewPureChecker::check() bool ViewPureChecker::check()
{ {
// The bool means "enforce view with errors". vector<ContractDefinition const*> contracts;
vector<pair<ContractDefinition const*, bool>> contracts;
for (auto const& node: m_ast) for (auto const& node: m_ast)
{ {
SourceUnit const* source = dynamic_cast<SourceUnit const*>(node.get()); SourceUnit const* source = dynamic_cast<SourceUnit const*>(node.get());
solAssert(source, ""); solAssert(source, "");
bool enforceView = source->annotation().experimentalFeatures.count(ExperimentalFeature::V050); contracts += source->filteredNodes<ContractDefinition>(source->nodes());
for (ContractDefinition const* c: source->filteredNodes<ContractDefinition>(source->nodes()))
contracts.emplace_back(c, enforceView);
} }
// Check modifiers first to infer their state mutability. // Check modifiers first to infer their state mutability.
for (auto const& contract: contracts) for (auto const& contract: contracts)
{ for (ModifierDefinition const* mod: contract->functionModifiers())
m_enforceViewWithError = contract.second;
for (ModifierDefinition const* mod: contract.first->functionModifiers())
mod->accept(*this); mod->accept(*this);
}
for (auto const& contract: contracts) for (auto const& contract: contracts)
{ contract->accept(*this);
m_enforceViewWithError = contract.second;
contract.first->accept(*this);
}
return !m_errors; return !m_errors;
} }
@ -232,17 +223,20 @@ void ViewPureChecker::reportMutability(StateMutability _mutability, SourceLocati
{ {
if (m_currentFunction && m_currentFunction->stateMutability() < _mutability) if (m_currentFunction && m_currentFunction->stateMutability() < _mutability)
{ {
string text;
if (_mutability == StateMutability::View) if (_mutability == StateMutability::View)
text = m_errorReporter.typeError(
_location,
"Function declared as pure, but this expression (potentially) reads from the " "Function declared as pure, but this expression (potentially) reads from the "
"environment or state and thus requires \"view\"."; "environment or state and thus requires \"view\"."
);
else if (_mutability == StateMutability::NonPayable) else if (_mutability == StateMutability::NonPayable)
text = m_errorReporter.typeError(
_location,
"Function declared as " + "Function declared as " +
stateMutabilityToString(m_currentFunction->stateMutability()) + stateMutabilityToString(m_currentFunction->stateMutability()) +
", but this expression (potentially) modifies the state and thus " ", but this expression (potentially) modifies the state and thus "
"requires non-payable (the default) or payable."; "requires non-payable (the default) or payable."
);
else else
solAssert(false, ""); solAssert(false, "");
@ -251,13 +245,7 @@ void ViewPureChecker::reportMutability(StateMutability _mutability, SourceLocati
m_currentFunction->stateMutability() == StateMutability::Pure, m_currentFunction->stateMutability() == StateMutability::Pure,
"" ""
); );
if (!m_enforceViewWithError && m_currentFunction->stateMutability() == StateMutability::View)
m_errorReporter.warning(_location, text);
else
{
m_errors = true; m_errors = true;
m_errorReporter.typeError(_location, text);
}
} }
if (_mutability > m_currentBestMutability) if (_mutability > m_currentBestMutability)
m_currentBestMutability = _mutability; m_currentBestMutability = _mutability;

View File

@ -71,7 +71,6 @@ private:
ErrorReporter& m_errorReporter; ErrorReporter& m_errorReporter;
bool m_errors = false; bool m_errors = false;
bool m_enforceViewWithError = false;
StateMutability m_currentBestMutability = StateMutability::Payable; StateMutability m_currentBestMutability = StateMutability::Payable;
FunctionDefinition const* m_currentFunction = nullptr; FunctionDefinition const* m_currentFunction = nullptr;
std::map<ModifierDefinition const*, StateMutability> m_inferredMutability; std::map<ModifierDefinition const*, StateMutability> m_inferredMutability;