aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-09-07 00:14:13 +0800
committerGitHub <noreply@github.com>2016-09-07 00:14:13 +0800
commitfbe0edb32c973166efbd5c0ac556f37fd38584d6 (patch)
treeb3ffbfdbb29a29b77a8ea403cf6e155cf9a0af46
parente8cb4d28970befb4c3e5052078e1b13812a44256 (diff)
parent65c4e65cb3c8bf5ea1139fb7359e053824667c83 (diff)
downloaddexon-solidity-fbe0edb32c973166efbd5c0ac556f37fd38584d6.tar.gz
dexon-solidity-fbe0edb32c973166efbd5c0ac556f37fd38584d6.tar.zst
dexon-solidity-fbe0edb32c973166efbd5c0ac556f37fd38584d6.zip
Merge pull request #1019 from ethereum/constructor-modifier
Enforce constructor visibility
-rw-r--r--libsolidity/analysis/TypeChecker.cpp2
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp10
2 files changed, 12 insertions, 0 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 41a5d39e..d9c54f75 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -80,6 +80,8 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor.");
if (function->isDeclaredConst())
typeError(function->location(), "Constructor cannot be defined as constant.");
+ if (function->visibility() != FunctionDefinition::Visibility::Public && function->visibility() != FunctionDefinition::Visibility::Internal)
+ typeError(function->location(), "Constructor must be public or internal.");
}
FunctionDefinition const* fallbackFunction = nullptr;
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 4de2c126..58736025 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -3999,6 +3999,16 @@ BOOST_AUTO_TEST_CASE(constant_constructor)
BOOST_CHECK(expectError(text, false) == Error::Type::TypeError);
}
+BOOST_AUTO_TEST_CASE(external_constructor)
+{
+ char const* text = R"(
+ contract test {
+ function test() external {}
+ }
+ )";
+ BOOST_CHECK(expectError(text, false) == Error::Type::TypeError);
+}
+
BOOST_AUTO_TEST_SUITE_END()