diff options
-rw-r--r-- | libsolidity/analysis/ViewPureChecker.cpp | 38 | ||||
-rw-r--r-- | libsolidity/analysis/ViewPureChecker.h | 1 |
2 files changed, 13 insertions, 26 deletions
diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index 107eb3aa..18c642c3 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -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; diff --git a/libsolidity/analysis/ViewPureChecker.h b/libsolidity/analysis/ViewPureChecker.h index 0b882cd8..3db52e7e 100644 --- a/libsolidity/analysis/ViewPureChecker.h +++ b/libsolidity/analysis/ViewPureChecker.h @@ -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; |