Replace some fatal errors when resolving references with normal ones

This commit is contained in:
Federico Bond 2017-10-26 11:02:36 -03:00
parent eba46a65fc
commit 600e66e605
3 changed files with 22 additions and 14 deletions

View File

@ -2,6 +2,7 @@
Features: Features:
* Commandline interface: Support strict mode of assembly with the ``--strict--assembly`` switch. * Commandline interface: Support strict mode of assembly with the ``--strict--assembly`` switch.
* Compiler now continues resolving references after the first error.
* Limit the number of warnings raised for creating abstract contracts. * Limit the number of warnings raised for creating abstract contracts.
* Inline Assembly: Issue warning for using jump labels (already existed for jump instructions). * Inline Assembly: Issue warning for using jump labels (already existed for jump instructions).
* Inline Assembly: Support some restricted tokens (return, byte, address) as identifiers in Julia mode. * Inline Assembly: Support some restricted tokens (return, byte, address) as identifiers in Julia mode.

View File

@ -47,7 +47,7 @@ bool ReferencesResolver::visit(Identifier const& _identifier)
{ {
auto declarations = m_resolver.nameFromCurrentScope(_identifier.name()); auto declarations = m_resolver.nameFromCurrentScope(_identifier.name());
if (declarations.empty()) if (declarations.empty())
fatalDeclarationError(_identifier.location(), "Undeclared identifier."); declarationError(_identifier.location(), "Undeclared identifier.");
else if (declarations.size() == 1) else if (declarations.size() == 1)
_identifier.annotation().referencedDeclaration = declarations.front(); _identifier.annotation().referencedDeclaration = declarations.front();
else else
@ -90,7 +90,10 @@ void ReferencesResolver::endVisit(UserDefinedTypeName const& _typeName)
{ {
Declaration const* declaration = m_resolver.pathFromCurrentScope(_typeName.namePath()); Declaration const* declaration = m_resolver.pathFromCurrentScope(_typeName.namePath());
if (!declaration) if (!declaration)
fatalDeclarationError(_typeName.location(), "Identifier not found or not unique."); {
declarationError(_typeName.location(), "Identifier not found or not unique.");
return;
}
_typeName.annotation().referencedDeclaration = declaration; _typeName.annotation().referencedDeclaration = declaration;
@ -101,7 +104,7 @@ void ReferencesResolver::endVisit(UserDefinedTypeName const& _typeName)
else if (ContractDefinition const* contract = dynamic_cast<ContractDefinition const*>(declaration)) else if (ContractDefinition const* contract = dynamic_cast<ContractDefinition const*>(declaration))
_typeName.annotation().type = make_shared<ContractType>(*contract); _typeName.annotation().type = make_shared<ContractType>(*contract);
else else
fatalTypeError(_typeName.location(), "Name has to refer to a struct, enum or contract."); typeError(_typeName.location(), "Name has to refer to a struct, enum or contract.");
} }
void ReferencesResolver::endVisit(FunctionTypeName const& _typeName) void ReferencesResolver::endVisit(FunctionTypeName const& _typeName)
@ -112,17 +115,25 @@ void ReferencesResolver::endVisit(FunctionTypeName const& _typeName)
case VariableDeclaration::Visibility::External: case VariableDeclaration::Visibility::External:
break; break;
default: default:
fatalTypeError(_typeName.location(), "Invalid visibility, can only be \"external\" or \"internal\"."); typeError(_typeName.location(), "Invalid visibility, can only be \"external\" or \"internal\".");
return;
} }
if (_typeName.isPayable() && _typeName.visibility() != VariableDeclaration::Visibility::External) if (_typeName.isPayable() && _typeName.visibility() != VariableDeclaration::Visibility::External)
fatalTypeError(_typeName.location(), "Only external function types can be payable."); {
typeError(_typeName.location(), "Only external function types can be payable.");
return;
}
if (_typeName.visibility() == VariableDeclaration::Visibility::External) if (_typeName.visibility() == VariableDeclaration::Visibility::External)
for (auto const& t: _typeName.parameterTypes() + _typeName.returnParameterTypes()) for (auto const& t: _typeName.parameterTypes() + _typeName.returnParameterTypes())
{ {
solAssert(t->annotation().type, "Type not set for parameter."); solAssert(t->annotation().type, "Type not set for parameter.");
if (!t->annotation().type->canBeUsedExternally(false)) if (!t->annotation().type->canBeUsedExternally(false))
fatalTypeError(t->location(), "Internal type cannot be used for external function type."); {
typeError(t->location(), "Internal type cannot be used for external function type.");
return;
}
} }
_typeName.annotation().type = make_shared<FunctionType>(_typeName); _typeName.annotation().type = make_shared<FunctionType>(_typeName);
@ -322,17 +333,13 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
type = ref->copyForLocation(typeLoc, isPointer); type = ref->copyForLocation(typeLoc, isPointer);
} }
else if (varLoc != Location::Default && !ref) else if (varLoc != Location::Default && !ref)
fatalTypeError(_variable.location(), "Storage location can only be given for array or struct types."); typeError(_variable.location(), "Storage location can only be given for array or struct types.");
if (!type)
fatalTypeError(_variable.location(), "Invalid type name.");
_variable.annotation().type = type;
} }
else if (!_variable.canHaveAutoType()) else if (!_variable.canHaveAutoType())
fatalTypeError(_variable.location(), "Explicit type needed."); typeError(_variable.location(), "Explicit type needed.");
// otherwise we have a "var"-declaration whose type is resolved by the first assignment // otherwise we have a "var"-declaration whose type is resolved by the first assignment
_variable.annotation().type = type;
} }
void ReferencesResolver::typeError(SourceLocation const& _location, string const& _description) void ReferencesResolver::typeError(SourceLocation const& _location, string const& _description)

View File

@ -4050,7 +4050,7 @@ BOOST_AUTO_TEST_CASE(varM_disqualified_as_keyword)
} }
} }
)"; )";
CHECK_ERROR(text, DeclarationError, "Identifier not found or not unique."); CHECK_ERROR_ALLOW_MULTI(text, DeclarationError, "Identifier not found or not unique.");
} }
BOOST_AUTO_TEST_CASE(modifier_is_not_a_valid_typename) BOOST_AUTO_TEST_CASE(modifier_is_not_a_valid_typename)