diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-09-15 01:13:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-15 01:13:56 +0800 |
commit | 7dd372ce5c9ea1cacf2c70a16f0285bb74314db8 (patch) | |
tree | 338fbcdef0accc0605120bc3fca163098d5d74fc /libsolidity/analysis/ViewPureChecker.cpp | |
parent | 934b0d2f0daf0a45fb686ec5073dbd288d27f769 (diff) | |
parent | 24fd67b7db26f44ddc6b6db0b6f685d887762df0 (diff) | |
download | dexon-solidity-7dd372ce5c9ea1cacf2c70a16f0285bb74314db8.tar.gz dexon-solidity-7dd372ce5c9ea1cacf2c70a16f0285bb74314db8.tar.zst dexon-solidity-7dd372ce5c9ea1cacf2c70a16f0285bb74314db8.zip |
Merge pull request #2904 from ethereum/viewPure5
Enforce view with error for experimental 0.5.0.
Diffstat (limited to 'libsolidity/analysis/ViewPureChecker.cpp')
-rw-r--r-- | libsolidity/analysis/ViewPureChecker.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index 8f9d41c9..7f28c7d2 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -20,6 +20,7 @@ #include <libevmasm/SemanticInformation.h> #include <libsolidity/inlineasm/AsmData.h> +#include <libsolidity/ast/ExperimentalFeatures.h> #include <functional> @@ -102,22 +103,31 @@ private: bool ViewPureChecker::check() { - vector<ContractDefinition const*> contracts; + // The bool means "enforce view with errors". + map<ContractDefinition const*, bool> contracts; for (auto const& node: m_ast) { SourceUnit const* source = dynamic_cast<SourceUnit const*>(node.get()); solAssert(source, ""); - contracts += source->filteredNodes<ContractDefinition>(source->nodes()); + bool enforceView = source->annotation().experimentalFeatures.count(ExperimentalFeature::V050); + for (ContractDefinition const* c: source->filteredNodes<ContractDefinition>(source->nodes())) + contracts[c] = enforceView; } // Check modifiers first to infer their state mutability. - for (auto const* contract: contracts) - for (ModifierDefinition const* mod: contract->functionModifiers()) + for (auto const& contract: contracts) + { + m_enforceViewWithError = contract.second; + for (ModifierDefinition const* mod: contract.first->functionModifiers()) mod->accept(*this); + } - for (auto const* contract: contracts) - contract->accept(*this); + for (auto const& contract: contracts) + { + m_enforceViewWithError = contract.second; + contract.first->accept(*this); + } return !m_errors; } @@ -223,16 +233,18 @@ void ViewPureChecker::reportMutability(StateMutability _mutability, SourceLocati else solAssert(false, ""); - if (m_currentFunction->stateMutability() == StateMutability::View) - // TODO Change this to error with 0.5.0 + solAssert( + m_currentFunction->stateMutability() == StateMutability::View || + m_currentFunction->stateMutability() == StateMutability::Pure, + "" + ); + if (!m_enforceViewWithError && m_currentFunction->stateMutability() == StateMutability::View) m_errorReporter.warning(_location, text); - else if (m_currentFunction->stateMutability() == StateMutability::Pure) + else { m_errors = true; m_errorReporter.typeError(_location, text); } - else - solAssert(false, ""); } if (_mutability > m_currentBestMutability) m_currentBestMutability = _mutability; |