From c96e997a3c4c3a14f55bc31a09557ff85b0558af Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 3 Aug 2020 16:35:13 +0200 Subject: [PATCH] Fix member lookup for constructor in library. --- Changelog.md | 1 + libsolidity/ast/AST.h | 1 + libsolidity/ast/Types.cpp | 4 +++- .../memberLookup/constructor_as_potential_library_member.sol | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/libsolidity/syntaxTests/memberLookup/constructor_as_potential_library_member.sol diff --git a/Changelog.md b/Changelog.md index 2e857a89f..cff21081d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ Compiler Features: Bugfixes: * SMTChecker: Fix internal error on fixed bytes index access. + * References Resolver: Fix internal bug when using constructor for library. ### 0.7.0 (2020-07-28) diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index de358a9e7..28d71c2b7 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -792,6 +792,7 @@ public: m_body(_body) { solAssert(_kind == Token::Constructor || _kind == Token::Function || _kind == Token::Fallback || _kind == Token::Receive, ""); + solAssert(isOrdinary() == !name().empty(), ""); } void accept(ASTVisitor& _visitor) override; diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index ebe935502..a87ae4c3f 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -451,7 +451,7 @@ MemberList::MemberMap Type::boundFunctions(Type const& _type, ASTNode const& _sc ); for (FunctionDefinition const* function: library.definedFunctions()) { - if (!function->isVisibleAsLibraryMember() || seenFunctions.count(function)) + if (!function->isOrdinary() || !function->isVisibleAsLibraryMember() || seenFunctions.count(function)) continue; seenFunctions.insert(function); if (function->parameters().empty()) @@ -3838,6 +3838,8 @@ MemberList::MemberMap TypeType::nativeMembers(ASTNode const* _currentScope) cons { if (dynamic_cast(declaration)) continue; + if (declaration->name().empty()) + continue; if (!contract.isLibrary() && inDerivingScope && declaration->isVisibleInDerivedContracts()) { diff --git a/test/libsolidity/syntaxTests/memberLookup/constructor_as_potential_library_member.sol b/test/libsolidity/syntaxTests/memberLookup/constructor_as_potential_library_member.sol new file mode 100644 index 000000000..71b63faa5 --- /dev/null +++ b/test/libsolidity/syntaxTests/memberLookup/constructor_as_potential_library_member.sol @@ -0,0 +1,4 @@ +library L{ constructor() { L.x; } } +// ---- +// TypeError 7634: (11-33): Constructor cannot be defined in libraries. +// TypeError 9582: (27-30): Member "x" not found or not visible after argument-dependent lookup in type(library L).