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

View File

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