@@ -86,6 +86,7 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract)
8686
8787 checkDuplicateFunctions (_contract);
8888 checkDuplicateEvents (_contract);
89+ checkReceiveFunction (_contract);
8990 m_overrideChecker.check (_contract);
9091 checkBaseConstructorArguments (_contract);
9192 checkAbstractDefinitions (_contract);
@@ -162,6 +163,35 @@ void ContractLevelChecker::checkDuplicateEvents(ContractDefinition const& _contr
162163 findDuplicateDefinitions (events);
163164}
164165
166+ void ContractLevelChecker::checkReceiveFunction (ContractDefinition const & _contract)
167+ {
168+ for (FunctionDefinition const * function: _contract.definedFunctions ())
169+ {
170+ solAssert (function, " " );
171+ if (function->isReceive ())
172+ {
173+ if (function->libraryFunction ())
174+ m_errorReporter.declarationError (4549_error, function->location (), " Libraries cannot have receive ether functions." );
175+
176+ if (function->stateMutability () != StateMutability::Payable)
177+ m_errorReporter.declarationError (
178+ 7793_error,
179+ function->location (),
180+ " Receive ether function must be payable, but is \" " +
181+ stateMutabilityToString (function->stateMutability ()) +
182+ " \" ."
183+ );
184+ if (function->visibility () != Visibility::External)
185+ m_errorReporter.declarationError (4095_error, function->location (), " Receive ether function must be defined as \" external\" ." );
186+
187+ if (!function->returnParameters ().empty ())
188+ m_errorReporter.fatalDeclarationError (6899_error, function->returnParameterList ()->location (), " Receive ether function cannot return values." );
189+ if (!function->parameters ().empty ())
190+ m_errorReporter.fatalDeclarationError (6857_error, function->parameterList ().location (), " Receive ether function cannot take parameters." );
191+ }
192+ }
193+ }
194+
165195template <class T >
166196void ContractLevelChecker::findDuplicateDefinitions (map<string, vector<T>> const & _definitions)
167197{
0 commit comments