diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-17 05:19:08 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-21 18:03:55 +0800 |
commit | fe25bcf350bfb65ddb69bc5e7d3f65dfa6d23fa7 (patch) | |
tree | 687f73c7e2b1a6b752960dd6e3580788b673279f | |
parent | 83b90f3e8a3ee168ba00eff33c4443d00bbb8a57 (diff) | |
download | dexon-solidity-fe25bcf350bfb65ddb69bc5e7d3f65dfa6d23fa7.tar.gz dexon-solidity-fe25bcf350bfb65ddb69bc5e7d3f65dfa6d23fa7.tar.zst dexon-solidity-fe25bcf350bfb65ddb69bc5e7d3f65dfa6d23fa7.zip |
Library cannot have constructors
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 3 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 10 |
3 files changed, 14 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md index 7d026862..f1046032 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 0764bf67..e5660cde 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -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()) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index fb2686fc..fad1ca61 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -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"( |