Skip to content

Commit

Permalink
Raise error when using unimplemented internal library functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Aug 8, 2017
1 parent bea37e5 commit 1ada48f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 15 additions & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
24 changes: 24 additions & 0 deletions test/libsolidity/SolidityNameAndTypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()

}
Expand Down

0 comments on commit 1ada48f

Please sign in to comment.