aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-09-18 22:38:55 +0800
committerGitHub <noreply@github.com>2017-09-18 22:38:55 +0800
commit3a9a9db6d688f3a1ef3bbcb0a378bbd14779abde (patch)
tree736d85c93db1af500f61d9357198372c15c76744
parent068a593d9c7ab31d1048199d262da3702f188bd3 (diff)
parenta3380ea8d0e02da1eb68eb15906015faf4e8bc3c (diff)
downloaddexon-solidity-3a9a9db6d688f3a1ef3bbcb0a378bbd14779abde.tar.gz
dexon-solidity-3a9a9db6d688f3a1ef3bbcb0a378bbd14779abde.tar.zst
dexon-solidity-3a9a9db6d688f3a1ef3bbcb0a378bbd14779abde.zip
Merge pull request #2910 from ethereum/fallback-restrict-external
Force fallback to be external (experimental 0.5.0 change)
-rw-r--r--Changelog.md3
-rw-r--r--libsolidity/analysis/TypeChecker.cpp5
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp32
3 files changed, 39 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md
index 376494e0..20630383 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,7 +1,7 @@
### 0.4.17 (unreleased)
Features:
- * Support ``pragma experimental v0.5.0;`` to turn on upcoming breaking changes.
+ * Support ``pragma experimental "v0.5.0";`` to turn on upcoming breaking changes.
* Code Generator: Added ``.selector`` member on external function types to retrieve their signature.
* Code Generator: Keep a single copy of encoding functions when using the experimental "ABIEncoderV2".
* Optimizer: Add new optimization step to remove unused ``JUMPDEST``s.
@@ -13,6 +13,7 @@ Features:
* Type Checker: Warn on using literals as tight packing parameters in ``keccak256``, ``sha3``, ``sha256`` and ``ripemd160``.
* Type Checker: Enforce ``view`` and ``pure``.
* Type Checker: Enforce ``view`` / ``constant`` with error as experimental 0.5.0 feature.
+ * Type Checker: Enforce fallback functions to be ``external`` as experimental 0.5.0 feature.
Bugfixes:
* ABI JSON: Include all overloaded events.
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index fe4207a3..030c8f6b 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -120,6 +120,11 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
m_errorReporter.typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters.");
if (!fallbackFunction->returnParameters().empty())
m_errorReporter.typeError(fallbackFunction->returnParameterList()->location(), "Fallback function cannot return values.");
+ if (
+ _contract.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050) &&
+ fallbackFunction->visibility() != FunctionDefinition::Visibility::External
+ )
+ m_errorReporter.typeError(fallbackFunction->location(), "Fallback function must be defined as \"external\".");
}
}
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index d9e6a63d..85acd8bf 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -6884,6 +6884,38 @@ BOOST_AUTO_TEST_CASE(tight_packing_literals)
CHECK_WARNING(text, "The type of \"int_const 1\" was inferred as uint8.");
}
+BOOST_AUTO_TEST_CASE(non_external_fallback)
+{
+ char const* text = R"(
+ pragma experimental "v0.5.0";
+ contract C {
+ function () external { }
+ }
+ )";
+ CHECK_WARNING(text, "Experimental features are turned on.");
+ text = R"(
+ pragma experimental "v0.5.0";
+ contract C {
+ function () internal { }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\".");
+ text = R"(
+ pragma experimental "v0.5.0";
+ contract C {
+ function () private { }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\".");
+ text = R"(
+ pragma experimental "v0.5.0";
+ contract C {
+ function () public { }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\".");
+}
+
BOOST_AUTO_TEST_SUITE_END()
}