mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow fallback function to return values.
This commit is contained in:
parent
f329d5e772
commit
21b6aa92ff
@ -425,7 +425,8 @@ Fallback Function
|
|||||||
*****************
|
*****************
|
||||||
|
|
||||||
A contract can have exactly one unnamed function. This function cannot have
|
A contract can have exactly one unnamed function. This function cannot have
|
||||||
arguments and is executed on a call to the contract if none of the other
|
arguments and cannot return anything.
|
||||||
|
It is executed on a call to the contract if none of the other
|
||||||
functions matches the given function identifier (or if no data was supplied at
|
functions matches the given function identifier (or if no data was supplied at
|
||||||
all).
|
all).
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
|
|||||||
fallbackFunction = function;
|
fallbackFunction = function;
|
||||||
if (!fallbackFunction->parameters().empty())
|
if (!fallbackFunction->parameters().empty())
|
||||||
typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters.");
|
typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters.");
|
||||||
|
if (!fallbackFunction->returnParameters().empty())
|
||||||
|
typeError(fallbackFunction->returnParameterList()->location(), "Fallback function cannot return values.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!function->isImplemented())
|
if (!function->isImplemented())
|
||||||
|
@ -1102,6 +1102,16 @@ BOOST_AUTO_TEST_CASE(fallback_function_with_arguments)
|
|||||||
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
|
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(fallback_function_with_return_parameters)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract C {
|
||||||
|
function() returns (uint) { }
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(fallback_function_twice)
|
BOOST_AUTO_TEST_CASE(fallback_function_twice)
|
||||||
{
|
{
|
||||||
char const* text = R"(
|
char const* text = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user