diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-04 20:35:06 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-08 18:58:00 +0800 |
commit | 1ada48f61e020a32c0c1f41394ded9a83d5ba57e (patch) | |
tree | cfa812e75c27bd565f922e02b1b819fe8044e962 | |
parent | bea37e5682d83b11988e51a16848319a59c39dd3 (diff) | |
download | dexon-solidity-1ada48f61e020a32c0c1f41394ded9a83d5ba57e.tar.gz dexon-solidity-1ada48f61e020a32c0c1f41394ded9a83d5ba57e.tar.zst dexon-solidity-1ada48f61e020a32c0c1f41394ded9a83d5ba57e.zip |
Raise error when using unimplemented internal library functions.
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 15 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 24 |
3 files changed, 40 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md index 8590f7b9..9087742d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ Bugfixes: * Type Checker: Constructors must be implemented if declared. * Type Checker: Do not mark overloaded functions as shadowing other functions. * Type Checker: Disallow the ``.gas()`` modifier on ``ecrecover``, ``sha256`` and ``ripemd160``. + * Type Checker: Raise error when using unimplemented internal library functions. ### 0.4.14 (2017-07-31) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index a9f5b931..fbdac1c7 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1403,6 +1403,21 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) else _functionCall.annotation().type = make_shared<TupleType>(functionType->returnParameterTypes()); + // Internal library functions must be implemented, because of inlining rules. + if ( + functionType->kind() == FunctionType::Kind::Internal && + functionType->hasDeclaration() && + dynamic_cast<FunctionDefinition const*>(&functionType->declaration()) + ) + { + FunctionDefinition const* function = dynamic_cast<FunctionDefinition const*>(&functionType->declaration()); + bool isLibraryFunction = + dynamic_cast<ContractDefinition const*>(function->scope()) && + dynamic_cast<ContractDefinition const*>(function->scope())->isLibrary(); + if (!function->isImplemented() && isLibraryFunction) + m_errorReporter.typeError(_functionCall.location(), "Inlined library function is lacking implementation."); + } + TypePointers parameterTypes = functionType->parameterTypes(); if (!functionType->takesArbitraryParameters() && parameterTypes.size() != arguments.size()) { diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index aaf1a449..ef83cc61 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -6536,6 +6536,30 @@ BOOST_AUTO_TEST_CASE(constructor_without_implementation) CHECK_ERROR(text, TypeError, "Constructor must be implemented if declared."); } +BOOST_AUTO_TEST_CASE(calling_unimplemented_internal_functions) +{ + char const* text = R"( + contract C { + function f() internal; + function g() { f(); } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} + +BOOST_AUTO_TEST_CASE(calling_unimplemented_internal_library_functions) +{ + char const* text = R"( + library L { + function f() internal; + } + contract C { + function g() { L.f(); } + } + )"; + CHECK_ERROR(text, TypeError, "Inlined library function is lacking implementation."); +} + BOOST_AUTO_TEST_SUITE_END() } |