diff --git a/Changelog.md b/Changelog.md index 9a835e07b..c173b239b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ ### 0.5.9 (unreleased) Language Features: + * Static Analyzer: Disallow libraries calling themselves externally. Compiler Features: diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index d6602c11d..2a0aaddcb 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -309,6 +309,19 @@ bool StaticAnalyzer::visit(FunctionCall const& _functionCall) "Arithmetic modulo zero." ); } + if ( + m_currentContract->isLibrary() && + functionType->kind() == FunctionType::Kind::DelegateCall && + functionType->declaration().scope() == m_currentContract + ) + m_errorReporter.typeError( + _functionCall.location(), + SecondarySourceLocation().append( + "The function declaration is here:", + functionType->declaration().scope()->location() + ), + "Libraries cannot call their own functions externally." + ); } return true; } diff --git a/test/libsolidity/syntaxTests/visibility/library_self_delegatecall.sol b/test/libsolidity/syntaxTests/visibility/library_self_delegatecall.sol new file mode 100644 index 000000000..0f0254206 --- /dev/null +++ b/test/libsolidity/syntaxTests/visibility/library_self_delegatecall.sol @@ -0,0 +1,13 @@ +library L1 { + using L1 for *; + function f() public pure returns (uint r) { return r.g(); } + function g(uint) public pure returns (uint) { return 2; } +} + +library L2 { + using L1 for *; + function f() public pure returns (uint r) { return r.g(); } + function g(uint) public pure returns (uint) { return 2; } +} +// ---- +// TypeError: (88-93): Libraries cannot call their own functions externally.