ViewPureChecker: Extract reportFunctionCallMutability() helper from endVisit(FunctionCall)

This commit is contained in:
wechman 2022-07-12 12:00:23 +02:00 committed by Kamil Śliwak
parent 27df07c4ce
commit edb4bfa398
2 changed files with 14 additions and 5 deletions

View File

@ -323,16 +323,23 @@ ViewPureChecker::MutabilityAndLocation const& ViewPureChecker::modifierMutabilit
return m_inferredMutability.at(&_modifier); 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) void ViewPureChecker::endVisit(FunctionCall const& _functionCall)
{ {
if (*_functionCall.annotation().kind != FunctionCallKind::FunctionCall) if (*_functionCall.annotation().kind != FunctionCallKind::FunctionCall)
return; return;
StateMutability mutability = dynamic_cast<FunctionType const&>(*_functionCall.expression().annotation().type).stateMutability(); reportFunctionCallMutability(
// We only require "nonpayable" to call a payble function. dynamic_cast<FunctionType const&>(*_functionCall.expression().annotation().type).stateMutability(),
if (mutability == StateMutability::Payable) _functionCall.location()
mutability = StateMutability::NonPayable; );
reportMutability(mutability, _functionCall.location());
} }
bool ViewPureChecker::visit(MemberAccess const& _memberAccess) bool ViewPureChecker::visit(MemberAccess const& _memberAccess)

View File

@ -73,6 +73,8 @@ private:
std::optional<langutil::SourceLocation> const& _nestedLocation = {} std::optional<langutil::SourceLocation> const& _nestedLocation = {}
); );
void reportFunctionCallMutability(StateMutability _mutability, langutil::SourceLocation const& _location);
/// Determines the mutability of modifier if not already cached. /// Determines the mutability of modifier if not already cached.
MutabilityAndLocation const& modifierMutability(ModifierDefinition const& _modifier); MutabilityAndLocation const& modifierMutability(ModifierDefinition const& _modifier);