mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2763 from ethereum/library-constructor
Library cannot have constructors
This commit is contained in:
commit
48651fc057
@ -10,9 +10,10 @@ Features:
|
|||||||
* Type Checker: Warn about shifting a literal.
|
* Type Checker: Warn about shifting a literal.
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
* Assembly Parser: Be more strict about number literals.
|
||||||
* Parser: Enforce commas between array and tuple elements.
|
* Parser: Enforce commas between array and tuple elements.
|
||||||
* Parser: Limit maximum recursion depth.
|
* Parser: Limit maximum recursion depth.
|
||||||
* Assembly Parser: Be more strict about number literals.
|
* Type Checker: Disallow constructors in libraries.
|
||||||
|
|
||||||
### 0.4.15 (2017-08-08)
|
### 0.4.15 (2017-08-08)
|
||||||
|
|
||||||
|
@ -546,6 +546,9 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
|
|||||||
if (_function.isConstructor())
|
if (_function.isConstructor())
|
||||||
m_errorReporter.typeError(_function.location(), "Constructor cannot be defined in interfaces.");
|
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())
|
if (_function.isImplemented())
|
||||||
_function.body().accept(*this);
|
_function.body().accept(*this);
|
||||||
else if (_function.isConstructor())
|
else if (_function.isConstructor())
|
||||||
|
@ -3055,6 +3055,16 @@ BOOST_AUTO_TEST_CASE(library_having_variables)
|
|||||||
CHECK_ERROR(text, TypeError, "Library cannot have non-constant state 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)
|
BOOST_AUTO_TEST_CASE(valid_library)
|
||||||
{
|
{
|
||||||
char const* text = R"(
|
char const* text = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user