Reject constant modifier on the fallback function

This commit is contained in:
Alex Beregszaszi 2016-08-26 20:01:47 +01:00
parent f687635e47
commit 6ec40b3cde
4 changed files with 13 additions and 3 deletions

View File

@ -94,6 +94,8 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
fallbackFunction = function; fallbackFunction = function;
if (_contract.isLibrary()) if (_contract.isLibrary())
typeError(fallbackFunction->location(), "Libraries cannot have fallback functions."); typeError(fallbackFunction->location(), "Libraries cannot have fallback functions.");
if (fallbackFunction->isDeclaredConst())
typeError(fallbackFunction->location(), "Fallback function cannot be declared constant.");
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()) if (!fallbackFunction->returnParameters().empty())

View File

@ -81,7 +81,6 @@ string InterfaceHandler::abiInterface(ContractDefinition const& _contractDef)
solAssert(!!externalFunctionType, ""); solAssert(!!externalFunctionType, "");
Json::Value method; Json::Value method;
method["type"] = "fallback"; method["type"] = "fallback";
method["constant"] = externalFunctionType->isConstant();
method["payable"] = externalFunctionType->isPayable(); method["payable"] = externalFunctionType->isPayable();
abi.append(method); abi.append(method);
} }

View File

@ -644,7 +644,6 @@ BOOST_AUTO_TEST_CASE(include_fallback_function)
char const* interface = R"( char const* interface = R"(
[ [
{ {
"constant" : false,
"payable": false, "payable": false,
"type" : "fallback" "type" : "fallback"
} }
@ -696,7 +695,6 @@ BOOST_AUTO_TEST_CASE(payable_fallback_unction)
char const* interface = R"( char const* interface = R"(
[ [
{ {
"constant" : false,
"payable": true, "payable": true,
"type" : "fallback" "type" : "fallback"
} }

View File

@ -1124,6 +1124,17 @@ BOOST_AUTO_TEST_CASE(fallback_function_with_return_parameters)
BOOST_CHECK(expectError(text) == Error::Type::TypeError); 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) BOOST_AUTO_TEST_CASE(fallback_function_twice)
{ {
char const* text = R"( char const* text = R"(