Library cannot have constructors

This commit is contained in:
Alex Beregszaszi 2017-08-16 22:19:08 +01:00
parent 83b90f3e8a
commit fe25bcf350
3 changed files with 14 additions and 0 deletions

View File

@ -12,6 +12,7 @@ Features:
Bugfixes:
* Parser: Enforce commas between array and tuple elements.
* Parser: Limit maximum recursion depth.
* Type Checker: Disallow constructors in libraries.
### 0.4.15 (2017-08-08)

View File

@ -546,6 +546,9 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
if (_function.isConstructor())
m_errorReporter.typeError(_function.location(), "Constructor cannot be defined in interfaces.");
}
else if (m_scope->contractKind() == ContractDefinition::ContractKind::Library)
if (_function.isConstructor())
m_errorReporter.typeError(_function.location(), "Constructor cannot be defined in libraries.");
if (_function.isImplemented())
_function.body().accept(*this);
else if (_function.isConstructor())

View File

@ -3055,6 +3055,16 @@ BOOST_AUTO_TEST_CASE(library_having_variables)
CHECK_ERROR(text, TypeError, "Library cannot have non-constant state variables");
}
BOOST_AUTO_TEST_CASE(library_constructor)
{
char const* text = R"(
library Lib {
function Lib();
}
)";
CHECK_ERROR_ALLOW_MULTI(text, TypeError, "Constructor cannot be defined in libraries.");
}
BOOST_AUTO_TEST_CASE(valid_library)
{
char const* text = R"(