Check if using for refers to a library earlier.

This commit is contained in:
chriseth 2020-06-17 17:44:48 +02:00
parent 8d3c2ba6d9
commit 76468f19fe
6 changed files with 21 additions and 10 deletions

View File

@ -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)

View File

@ -395,6 +395,15 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
}
void DeclarationTypeChecker::endVisit(UsingForDirective const& _usingFor)
{
ContractDefinition const* library = dynamic_cast<ContractDefinition const*>(
_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();

View File

@ -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;

View File

@ -313,15 +313,6 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
}
}
void TypeChecker::endVisit(UsingForDirective const& _usingFor)
{
ContractDefinition const* library = dynamic_cast<ContractDefinition const*>(
_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())

View File

@ -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;

View File

@ -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.