diff --git a/Changelog.md b/Changelog.md index 22f1d1e5d..2c855de10 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ Compiler Features: Bugfixes: * NatSpec: Do not consider ``////`` and ``/***`` as NatSpec comments. + * Type Checker: Fix internal error related to ``using for`` applied to non-libraries. ### 0.6.10 (2020-06-11) diff --git a/libsolidity/analysis/DeclarationTypeChecker.cpp b/libsolidity/analysis/DeclarationTypeChecker.cpp index b5b27222d..07e8f6066 100644 --- a/libsolidity/analysis/DeclarationTypeChecker.cpp +++ b/libsolidity/analysis/DeclarationTypeChecker.cpp @@ -395,6 +395,15 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) } +void DeclarationTypeChecker::endVisit(UsingForDirective const& _usingFor) +{ + ContractDefinition const* library = dynamic_cast( + _usingFor.libraryName().annotation().referencedDeclaration + ); + if (!library || !library->isLibrary()) + m_errorReporter.fatalTypeError(4357_error, _usingFor.libraryName().location(), "Library name expected."); +} + bool DeclarationTypeChecker::check(ASTNode const& _node) { auto watcher = m_errorReporter.errorWatcher(); diff --git a/libsolidity/analysis/DeclarationTypeChecker.h b/libsolidity/analysis/DeclarationTypeChecker.h index 764a66e1d..0edd97bd9 100644 --- a/libsolidity/analysis/DeclarationTypeChecker.h +++ b/libsolidity/analysis/DeclarationTypeChecker.h @@ -58,6 +58,7 @@ private: void endVisit(ArrayTypeName const& _typeName) override; void endVisit(VariableDeclaration const& _variable) override; bool visit(StructDefinition const& _struct) override; + void endVisit(UsingForDirective const& _usingForDirective) override; langutil::ErrorReporter& m_errorReporter; langutil::EVMVersion m_evmVersion; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 4a99764c3..3bdb2de90 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -313,15 +313,6 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance) } } -void TypeChecker::endVisit(UsingForDirective const& _usingFor) -{ - ContractDefinition const* library = dynamic_cast( - _usingFor.libraryName().annotation().referencedDeclaration - ); - if (!library || !library->isLibrary()) - m_errorReporter.fatalTypeError(4357_error, _usingFor.libraryName().location(), "Library name expected."); -} - void TypeChecker::endVisit(ModifierDefinition const& _modifier) { if (!_modifier.isImplemented() && !_modifier.virtualSemantics()) diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index 732f6275a..9e5f9470f 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -111,7 +111,6 @@ private: ); void endVisit(InheritanceSpecifier const& _inheritance) override; - void endVisit(UsingForDirective const& _usingFor) override; void endVisit(ModifierDefinition const& _modifier) override; bool visit(FunctionDefinition const& _function) override; bool visit(VariableDeclaration const& _variable) override; diff --git a/test/libsolidity/syntaxTests/bound/bound_to_struct.sol b/test/libsolidity/syntaxTests/bound/bound_to_struct.sol new file mode 100644 index 000000000..eefe9f6bf --- /dev/null +++ b/test/libsolidity/syntaxTests/bound/bound_to_struct.sol @@ -0,0 +1,10 @@ +contract C { + struct S { uint t; } + function r() public { + S memory x; + x.d; + } + using S for S; +} +// ---- +// TypeError: (113-114): Library name expected.