Merge pull request #1019 from ethereum/constructor-modifier

Enforce constructor visibility
This commit is contained in:
chriseth 2016-09-06 18:14:13 +02:00 committed by GitHub
commit fbe0edb32c
2 changed files with 12 additions and 0 deletions

View File

@ -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;

View File

@ -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()