aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-09-06 21:51:45 +0800
committerGitHub <noreply@github.com>2016-09-06 21:51:45 +0800
commit358812569287976001ee1f6cec077038d3fcc937 (patch)
tree78ed0c2ea41b6984edb976f58998d69e8a27426a
parentfb73da30d83624a1579fd10210946af0e82394b0 (diff)
parent6ec40b3cdeca667cea2222755c6e145c72279b1d (diff)
downloaddexon-solidity-358812569287976001ee1f6cec077038d3fcc937.tar
dexon-solidity-358812569287976001ee1f6cec077038d3fcc937.tar.gz
dexon-solidity-358812569287976001ee1f6cec077038d3fcc937.tar.bz2
dexon-solidity-358812569287976001ee1f6cec077038d3fcc937.tar.lz
dexon-solidity-358812569287976001ee1f6cec077038d3fcc937.tar.xz
dexon-solidity-358812569287976001ee1f6cec077038d3fcc937.tar.zst
dexon-solidity-358812569287976001ee1f6cec077038d3fcc937.zip
Merge pull request #1014 from ethereum/strict-fallback
Reject constant modifier on the fallback function
-rw-r--r--libsolidity/analysis/TypeChecker.cpp2
-rw-r--r--libsolidity/interface/InterfaceHandler.cpp1
-rw-r--r--test/libsolidity/SolidityABIJSON.cpp2
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp11
4 files changed, 13 insertions, 3 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 06e26a76..fc1b1f59 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -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())
diff --git a/libsolidity/interface/InterfaceHandler.cpp b/libsolidity/interface/InterfaceHandler.cpp
index 6e3ae78f..de16a372 100644
--- a/libsolidity/interface/InterfaceHandler.cpp
+++ b/libsolidity/interface/InterfaceHandler.cpp
@@ -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);
}
diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp
index 185ba3bf..073d7d97 100644
--- a/test/libsolidity/SolidityABIJSON.cpp
+++ b/test/libsolidity/SolidityABIJSON.cpp
@@ -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"
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index ab0f9c7b..882557fd 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -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"(