Merge pull request #5950 from ethereum/unreachable-to-assert

Turn unreachable error statements into asserts
This commit is contained in:
chriseth 2019-02-07 12:18:47 +01:00 committed by GitHub
commit 646c9a9e1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -287,8 +287,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
bool TypeChecker::visit(StructDefinition const& _struct) bool TypeChecker::visit(StructDefinition const& _struct)
{ {
for (ASTPointer<VariableDeclaration> const& member: _struct.members()) for (ASTPointer<VariableDeclaration> const& member: _struct.members())
if (!type(*member)->canBeStored()) solAssert(type(*member)->canBeStored(), "Type cannot be used in struct.");
m_errorReporter.typeError(member->location(), "Type cannot be used in struct.");
// Check recursion, fatal error if detected. // Check recursion, fatal error if detected.
auto visitor = [&](StructDefinition const& _struct, CycleDetector<StructDefinition>& _cycleDetector, size_t _depth) auto visitor = [&](StructDefinition const& _struct, CycleDetector<StructDefinition>& _cycleDetector, size_t _depth)
@ -615,8 +614,7 @@ void TypeChecker::endVisit(FunctionTypeName const& _funType)
{ {
FunctionType const& fun = dynamic_cast<FunctionType const&>(*_funType.annotation().type); FunctionType const& fun = dynamic_cast<FunctionType const&>(*_funType.annotation().type);
if (fun.kind() == FunctionType::Kind::External) if (fun.kind() == FunctionType::Kind::External)
if (!fun.canBeUsedExternally(false)) solAssert(fun.canBeUsedExternally(false), "External function type uses internal types.");
m_errorReporter.typeError(_funType.location(), "External function type uses internal types.");
} }
bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
@ -887,8 +885,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
if (ref->dataStoredIn(DataLocation::Storage)) if (ref->dataStoredIn(DataLocation::Storage))
{ {
string errorText{"Uninitialized storage pointer."}; string errorText{"Uninitialized storage pointer."};
if (varDecl.referenceLocation() == VariableDeclaration::Location::Unspecified) solAssert(varDecl.referenceLocation() != VariableDeclaration::Location::Unspecified, "Expected a specified location at this point");
errorText += " Did you mean '<type> memory " + varDecl.name() + "'?";
solAssert(m_scope, ""); solAssert(m_scope, "");
m_errorReporter.declarationError(varDecl.location(), errorText); m_errorReporter.declarationError(varDecl.location(), errorText);
} }
@ -956,10 +953,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
solAssert(false, ""); solAssert(false, "");
} }
else if (*var.annotation().type == TupleType()) else if (*var.annotation().type == TupleType())
m_errorReporter.typeError( solAssert(false, "Cannot declare variable with void (empty tuple) type.");
var.location(),
"Cannot declare variable with void (empty tuple) type."
);
else if (valueComponentType->category() == Type::Category::RationalNumber) else if (valueComponentType->category() == Type::Category::RationalNumber)
{ {
string typeName = var.annotation().type->toString(true); string typeName = var.annotation().type->toString(true);