diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index 7483af892..076430e13 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -323,16 +323,23 @@ ViewPureChecker::MutabilityAndLocation const& ViewPureChecker::modifierMutabilit return m_inferredMutability.at(&_modifier); } +void ViewPureChecker::reportFunctionCallMutability(StateMutability _mutability, langutil::SourceLocation const& _location) +{ + // We only require "nonpayable" to call a payable function. + if (_mutability == StateMutability::Payable) + _mutability = StateMutability::NonPayable; + reportMutability(_mutability, _location); +} + void ViewPureChecker::endVisit(FunctionCall const& _functionCall) { if (*_functionCall.annotation().kind != FunctionCallKind::FunctionCall) return; - StateMutability mutability = dynamic_cast(*_functionCall.expression().annotation().type).stateMutability(); - // We only require "nonpayable" to call a payble function. - if (mutability == StateMutability::Payable) - mutability = StateMutability::NonPayable; - reportMutability(mutability, _functionCall.location()); + reportFunctionCallMutability( + dynamic_cast(*_functionCall.expression().annotation().type).stateMutability(), + _functionCall.location() + ); } bool ViewPureChecker::visit(MemberAccess const& _memberAccess) diff --git a/libsolidity/analysis/ViewPureChecker.h b/libsolidity/analysis/ViewPureChecker.h index b0abe8fd8..6ba1384ce 100644 --- a/libsolidity/analysis/ViewPureChecker.h +++ b/libsolidity/analysis/ViewPureChecker.h @@ -73,6 +73,8 @@ private: std::optional const& _nestedLocation = {} ); + void reportFunctionCallMutability(StateMutability _mutability, langutil::SourceLocation const& _location); + /// Determines the mutability of modifier if not already cached. MutabilityAndLocation const& modifierMutability(ModifierDefinition const& _modifier);