mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix checks for "using for ... global" for libraries.
This commit is contained in:
@@ -3638,11 +3638,36 @@ void TypeChecker::endVisit(Literal const& _literal)
|
||||
|
||||
void TypeChecker::endVisit(UsingForDirective const& _usingFor)
|
||||
{
|
||||
if (_usingFor.global())
|
||||
{
|
||||
if (m_currentContract || !_usingFor.typeName())
|
||||
{
|
||||
solAssert(m_errorReporter.hasErrors());
|
||||
return;
|
||||
}
|
||||
solAssert(_usingFor.typeName()->annotation().type);
|
||||
if (Declaration const* typeDefinition = _usingFor.typeName()->annotation().type->typeDefinition())
|
||||
{
|
||||
if (typeDefinition->scope() != m_currentSourceUnit)
|
||||
m_errorReporter.typeError(
|
||||
4117_error,
|
||||
_usingFor.location(),
|
||||
"Can only use \"global\" with types defined in the same source unit at file level."
|
||||
);
|
||||
}
|
||||
else
|
||||
m_errorReporter.typeError(
|
||||
8841_error,
|
||||
_usingFor.location(),
|
||||
"Can only use \"global\" with user-defined types."
|
||||
);
|
||||
}
|
||||
|
||||
if (!_usingFor.usesBraces())
|
||||
{
|
||||
solAssert(_usingFor.functionsOrLibrary().size() == 1);
|
||||
ContractDefinition const* library = dynamic_cast<ContractDefinition const*>(
|
||||
_usingFor.functionsOrLibrary().front()->annotation().referencedDeclaration
|
||||
_usingFor.functionsOrLibrary().front()->annotation().referencedDeclaration
|
||||
);
|
||||
solAssert(library && library->isLibrary());
|
||||
// No type checking for libraries
|
||||
@@ -3662,28 +3687,6 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
|
||||
);
|
||||
solAssert(normalizedType);
|
||||
|
||||
if (_usingFor.global())
|
||||
{
|
||||
if (m_currentContract)
|
||||
solAssert(m_errorReporter.hasErrors());
|
||||
if (Declaration const* typeDefinition = _usingFor.typeName()->annotation().type->typeDefinition())
|
||||
{
|
||||
if (typeDefinition->scope() != m_currentSourceUnit)
|
||||
m_errorReporter.typeError(
|
||||
4117_error,
|
||||
_usingFor.location(),
|
||||
"Can only use \"global\" with types defined in the same source unit at file level."
|
||||
);
|
||||
}
|
||||
else
|
||||
m_errorReporter.typeError(
|
||||
8841_error,
|
||||
_usingFor.location(),
|
||||
"Can only use \"global\" with user-defined types."
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
for (ASTPointer<IdentifierPath> const& path: _usingFor.functionsOrLibrary())
|
||||
{
|
||||
solAssert(path->annotation().referencedDeclaration);
|
||||
|
||||
Reference in New Issue
Block a user