mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move fallback function checks.
This commit is contained in:
parent
2a85152463
commit
4f4f623273
@ -41,6 +41,7 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract)
|
|||||||
checkAbstractFunctions(_contract);
|
checkAbstractFunctions(_contract);
|
||||||
checkBaseConstructorArguments(_contract);
|
checkBaseConstructorArguments(_contract);
|
||||||
checkConstructor(_contract);
|
checkConstructor(_contract);
|
||||||
|
checkFallbackFunction(_contract);
|
||||||
|
|
||||||
return Error::containsOnlyWarnings(m_errorReporter.errors());
|
return Error::containsOnlyWarnings(m_errorReporter.errors());
|
||||||
}
|
}
|
||||||
@ -359,3 +360,26 @@ void ContractLevelChecker::checkConstructor(ContractDefinition const& _contract)
|
|||||||
if (constructor->visibility() != FunctionDefinition::Visibility::Public && constructor->visibility() != FunctionDefinition::Visibility::Internal)
|
if (constructor->visibility() != FunctionDefinition::Visibility::Public && constructor->visibility() != FunctionDefinition::Visibility::Internal)
|
||||||
m_errorReporter.typeError(constructor->location(), "Constructor must be public or internal.");
|
m_errorReporter.typeError(constructor->location(), "Constructor must be public or internal.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContractLevelChecker::checkFallbackFunction(ContractDefinition const& _contract)
|
||||||
|
{
|
||||||
|
FunctionDefinition const* fallback = _contract.fallbackFunction();
|
||||||
|
if (!fallback)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_contract.isLibrary())
|
||||||
|
m_errorReporter.typeError(fallback->location(), "Libraries cannot have fallback functions.");
|
||||||
|
if (fallback->stateMutability() != StateMutability::NonPayable && fallback->stateMutability() != StateMutability::Payable)
|
||||||
|
m_errorReporter.typeError(
|
||||||
|
fallback->location(),
|
||||||
|
"Fallback function must be payable or non-payable, but is \"" +
|
||||||
|
stateMutabilityToString(fallback->stateMutability()) +
|
||||||
|
"\"."
|
||||||
|
);
|
||||||
|
if (!fallback->parameters().empty())
|
||||||
|
m_errorReporter.typeError(fallback->parameterList().location(), "Fallback function cannot take parameters.");
|
||||||
|
if (!fallback->returnParameters().empty())
|
||||||
|
m_errorReporter.typeError(fallback->returnParameterList()->location(), "Fallback function cannot return values.");
|
||||||
|
if (fallback->visibility() != FunctionDefinition::Visibility::External)
|
||||||
|
m_errorReporter.typeError(fallback->location(), "Fallback function must be defined as \"external\".");
|
||||||
|
}
|
||||||
|
@ -71,6 +71,7 @@ private:
|
|||||||
ASTNode const* _argumentNode
|
ASTNode const* _argumentNode
|
||||||
);
|
);
|
||||||
void checkConstructor(ContractDefinition const& _contract);
|
void checkConstructor(ContractDefinition const& _contract);
|
||||||
|
void checkFallbackFunction(ContractDefinition const& _contract);
|
||||||
|
|
||||||
langutil::ErrorReporter& m_errorReporter;
|
langutil::ErrorReporter& m_errorReporter;
|
||||||
};
|
};
|
||||||
|
@ -90,26 +90,6 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
|
|||||||
|
|
||||||
ASTNode::listAccept(_contract.baseContracts(), *this);
|
ASTNode::listAccept(_contract.baseContracts(), *this);
|
||||||
|
|
||||||
for (FunctionDefinition const* function: _contract.definedFunctions())
|
|
||||||
if (function->isFallback())
|
|
||||||
{
|
|
||||||
if (_contract.isLibrary())
|
|
||||||
m_errorReporter.typeError(function->location(), "Libraries cannot have fallback functions.");
|
|
||||||
if (function->stateMutability() != StateMutability::NonPayable && function->stateMutability() != StateMutability::Payable)
|
|
||||||
m_errorReporter.typeError(
|
|
||||||
function->location(),
|
|
||||||
"Fallback function must be payable or non-payable, but is \"" +
|
|
||||||
stateMutabilityToString(function->stateMutability()) +
|
|
||||||
"\"."
|
|
||||||
);
|
|
||||||
if (!function->parameters().empty())
|
|
||||||
m_errorReporter.typeError(function->parameterList().location(), "Fallback function cannot take parameters.");
|
|
||||||
if (!function->returnParameters().empty())
|
|
||||||
m_errorReporter.typeError(function->returnParameterList()->location(), "Fallback function cannot return values.");
|
|
||||||
if (function->visibility() != FunctionDefinition::Visibility::External)
|
|
||||||
m_errorReporter.typeError(function->location(), "Fallback function must be defined as \"external\".");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto const& n: _contract.subNodes())
|
for (auto const& n: _contract.subNodes())
|
||||||
n->accept(*this);
|
n->accept(*this);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user