Merge pull request #1014 from ethereum/strict-fallback

Reject constant modifier on the fallback function
This commit is contained in:
chriseth
2016-09-06 15:51:45 +02:00
committed by GitHub
4 changed files with 13 additions and 3 deletions
+2
View File
@@ -94,6 +94,8 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
fallbackFunction = function;
if (_contract.isLibrary())
typeError(fallbackFunction->location(), "Libraries cannot have fallback functions.");
if (fallbackFunction->isDeclaredConst())
typeError(fallbackFunction->location(), "Fallback function cannot be declared constant.");
if (!fallbackFunction->parameters().empty())
typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters.");
if (!fallbackFunction->returnParameters().empty())
@@ -81,7 +81,6 @@ string InterfaceHandler::abiInterface(ContractDefinition const& _contractDef)
solAssert(!!externalFunctionType, "");
Json::Value method;
method["type"] = "fallback";
method["constant"] = externalFunctionType->isConstant();
method["payable"] = externalFunctionType->isPayable();
abi.append(method);
}
-2
View File
@@ -644,7 +644,6 @@ BOOST_AUTO_TEST_CASE(include_fallback_function)
char const* interface = R"(
[
{
"constant" : false,
"payable": false,
"type" : "fallback"
}
@@ -696,7 +695,6 @@ BOOST_AUTO_TEST_CASE(payable_fallback_unction)
char const* interface = R"(
[
{
"constant" : false,
"payable": true,
"type" : "fallback"
}
@@ -1124,6 +1124,17 @@ BOOST_AUTO_TEST_CASE(fallback_function_with_return_parameters)
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
BOOST_AUTO_TEST_CASE(fallback_function_with_constant_modifier)
{
char const* text = R"(
contract C {
uint x;
function() constant { x = 2; }
}
)";
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
BOOST_AUTO_TEST_CASE(fallback_function_twice)
{
char const* text = R"(