mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix ICE related to receive function having parameters.
This commit is contained in:
@@ -86,6 +86,7 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract)
|
||||
|
||||
checkDuplicateFunctions(_contract);
|
||||
checkDuplicateEvents(_contract);
|
||||
checkReceiveFunction(_contract);
|
||||
m_overrideChecker.check(_contract);
|
||||
checkBaseConstructorArguments(_contract);
|
||||
checkAbstractDefinitions(_contract);
|
||||
@@ -162,6 +163,35 @@ void ContractLevelChecker::checkDuplicateEvents(ContractDefinition const& _contr
|
||||
findDuplicateDefinitions(events);
|
||||
}
|
||||
|
||||
void ContractLevelChecker::checkReceiveFunction(ContractDefinition const& _contract)
|
||||
{
|
||||
for (FunctionDefinition const* function: _contract.definedFunctions())
|
||||
{
|
||||
solAssert(function, "");
|
||||
if (function->isReceive())
|
||||
{
|
||||
if (function->libraryFunction())
|
||||
m_errorReporter.declarationError(4549_error, function->location(), "Libraries cannot have receive ether functions.");
|
||||
|
||||
if (function->stateMutability() != StateMutability::Payable)
|
||||
m_errorReporter.declarationError(
|
||||
7793_error,
|
||||
function->location(),
|
||||
"Receive ether function must be payable, but is \"" +
|
||||
stateMutabilityToString(function->stateMutability()) +
|
||||
"\"."
|
||||
);
|
||||
if (function->visibility() != Visibility::External)
|
||||
m_errorReporter.declarationError(4095_error, function->location(), "Receive ether function must be defined as \"external\".");
|
||||
|
||||
if (!function->returnParameters().empty())
|
||||
m_errorReporter.fatalDeclarationError(6899_error, function->returnParameterList()->location(), "Receive ether function cannot return values.");
|
||||
if (!function->parameters().empty())
|
||||
m_errorReporter.fatalDeclarationError(6857_error, function->parameterList().location(), "Receive ether function cannot take parameters.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void ContractLevelChecker::findDuplicateDefinitions(map<string, vector<T>> const& _definitions)
|
||||
{
|
||||
|
||||
@@ -63,6 +63,7 @@ private:
|
||||
/// arguments and that there is at most one constructor.
|
||||
void checkDuplicateFunctions(ContractDefinition const& _contract);
|
||||
void checkDuplicateEvents(ContractDefinition const& _contract);
|
||||
void checkReceiveFunction(ContractDefinition const& _contract);
|
||||
template <class T>
|
||||
void findDuplicateDefinitions(std::map<std::string, std::vector<T>> const& _definitions);
|
||||
/// Checks for unimplemented functions and modifiers.
|
||||
|
||||
@@ -489,8 +489,6 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
|
||||
|
||||
if (_function.isFallback())
|
||||
typeCheckFallbackFunction(_function);
|
||||
else if (_function.isReceive())
|
||||
typeCheckReceiveFunction(_function);
|
||||
else if (_function.isConstructor())
|
||||
typeCheckConstructor(_function);
|
||||
|
||||
@@ -1881,30 +1879,6 @@ void TypeChecker::typeCheckFallbackFunction(FunctionDefinition const& _function)
|
||||
}
|
||||
}
|
||||
|
||||
void TypeChecker::typeCheckReceiveFunction(FunctionDefinition const& _function)
|
||||
{
|
||||
solAssert(_function.isReceive(), "");
|
||||
|
||||
if (_function.libraryFunction())
|
||||
m_errorReporter.typeError(4549_error, _function.location(), "Libraries cannot have receive ether functions.");
|
||||
|
||||
if (_function.stateMutability() != StateMutability::Payable)
|
||||
m_errorReporter.typeError(
|
||||
7793_error,
|
||||
_function.location(),
|
||||
"Receive ether function must be payable, but is \"" +
|
||||
stateMutabilityToString(_function.stateMutability()) +
|
||||
"\"."
|
||||
);
|
||||
if (_function.visibility() != Visibility::External)
|
||||
m_errorReporter.typeError(4095_error, _function.location(), "Receive ether function must be defined as \"external\".");
|
||||
if (!_function.returnParameters().empty())
|
||||
m_errorReporter.typeError(6899_error, _function.returnParameterList()->location(), "Receive ether function cannot return values.");
|
||||
if (!_function.parameters().empty())
|
||||
m_errorReporter.typeError(6857_error, _function.parameterList().location(), "Receive ether function cannot take parameters.");
|
||||
}
|
||||
|
||||
|
||||
void TypeChecker::typeCheckConstructor(FunctionDefinition const& _function)
|
||||
{
|
||||
solAssert(_function.isConstructor(), "");
|
||||
|
||||
@@ -96,7 +96,6 @@ private:
|
||||
);
|
||||
|
||||
void typeCheckFallbackFunction(FunctionDefinition const& _function);
|
||||
void typeCheckReceiveFunction(FunctionDefinition const& _function);
|
||||
void typeCheckConstructor(FunctionDefinition const& _function);
|
||||
|
||||
/// Performs general number and type checks of arguments against function call and struct ctor FunctionCall node parameters.
|
||||
|
||||
Reference in New Issue
Block a user