Shorten a couple of lines

This commit is contained in:
a3d4 2020-05-21 17:38:47 +02:00
parent 38e65a909a
commit 5870253b00
4 changed files with 71 additions and 15 deletions

View File

@ -103,7 +103,11 @@ bool DeclarationTypeChecker::visit(StructDefinition const& _struct)
auto visitor = [&](StructDefinition const& _struct, auto& _cycleDetector, size_t _depth)
{
if (_depth >= 256)
m_errorReporter.fatalDeclarationError(5651_error, _struct.location(), "Struct definition exhausts cyclic dependency validator.");
m_errorReporter.fatalDeclarationError(
5651_error,
_struct.location(),
"Struct definition exhausts cyclic dependency validator."
);
for (ASTPointer<VariableDeclaration> const& member: _struct.members())
{
@ -146,9 +150,14 @@ void DeclarationTypeChecker::endVisit(UserDefinedTypeName const& _typeName)
else
{
_typeName.annotation().type = TypeProvider::emptyTuple();
m_errorReporter.fatalTypeError(9755_error, _typeName.location(), "Name has to refer to a struct, enum or contract.");
m_errorReporter.fatalTypeError(
9755_error,
_typeName.location(),
"Name has to refer to a struct, enum or contract."
);
}
}
bool DeclarationTypeChecker::visit(FunctionTypeName const& _typeName)
{
if (_typeName.annotation().type)
@ -166,18 +175,27 @@ bool DeclarationTypeChecker::visit(FunctionTypeName const& _typeName)
case Visibility::External:
break;
default:
m_errorReporter.fatalTypeError(7653_error, _typeName.location(), "Invalid visibility, can only be \"external\" or \"internal\".");
m_errorReporter.fatalTypeError(
7653_error,
_typeName.location(),
"Invalid visibility, can only be \"external\" or \"internal\"."
);
return false;
}
if (_typeName.isPayable() && _typeName.visibility() != Visibility::External)
{
m_errorReporter.fatalTypeError(6138_error, _typeName.location(), "Only external function types can be payable.");
m_errorReporter.fatalTypeError(
6138_error,
_typeName.location(),
"Only external function types can be payable."
);
return false;
}
_typeName.annotation().type = TypeProvider::function(_typeName);
return false;
}
void DeclarationTypeChecker::endVisit(Mapping const& _mapping)
{
if (_mapping.annotation().type)
@ -227,7 +245,11 @@ void DeclarationTypeChecker::endVisit(ArrayTypeName const& _typeName)
return;
}
if (baseType->storageBytes() == 0)
m_errorReporter.fatalTypeError(9390_error, _typeName.baseType().location(), "Illegal base type of storage size zero for array.");
m_errorReporter.fatalTypeError(
9390_error,
_typeName.baseType().location(),
"Illegal base type of storage size zero for array."
);
if (Expression const* length = _typeName.length())
{
TypePointer& lengthTypeGeneric = length->annotation().type;
@ -236,7 +258,11 @@ void DeclarationTypeChecker::endVisit(ArrayTypeName const& _typeName)
RationalNumberType const* lengthType = dynamic_cast<RationalNumberType const*>(lengthTypeGeneric);
u256 lengthValue = 0;
if (!lengthType || !lengthType->mobileType())
m_errorReporter.typeError(8922_error, length->location(), "Invalid array length, expected integer literal or constant expression.");
m_errorReporter.typeError(
8922_error,
length->location(),
"Invalid array length, expected integer literal or constant expression."
);
else if (lengthType->isZero())
m_errorReporter.typeError(1220_error, length->location(), "Array with zero length specified.");
else if (lengthType->isFractional())
@ -250,15 +276,24 @@ void DeclarationTypeChecker::endVisit(ArrayTypeName const& _typeName)
else
_typeName.annotation().type = TypeProvider::array(DataLocation::Storage, baseType);
}
void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
{
if (_variable.annotation().type)
return;
if (_variable.isConstant() && !_variable.isStateVariable())
m_errorReporter.declarationError(1788_error, _variable.location(), "The \"constant\" keyword can only be used for state variables.");
m_errorReporter.declarationError(
1788_error,
_variable.location(),
"The \"constant\" keyword can only be used for state variables."
);
if (_variable.immutable() && !_variable.isStateVariable())
m_errorReporter.declarationError(8297_error, _variable.location(), "The \"immutable\" keyword can only be used for state variables.");
m_errorReporter.declarationError(
8297_error,
_variable.location(),
"The \"immutable\" keyword can only be used for state variables."
);
if (!_variable.typeName())
{

View File

@ -69,13 +69,15 @@ bool DocStringAnalyser::visit(VariableDeclaration const& _variable)
if (_variable.annotation().docTags.count("notice") > 0)
m_errorReporter.warning(
7816_error, _variable.documentation()->location(),
"Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly."
"Documentation tag on non-public state variables will be disallowed in 0.7.0. "
"You will need to use the @dev tag explicitly."
);
}
if (_variable.annotation().docTags.count("title") > 0 || _variable.annotation().docTags.count("author") > 0)
m_errorReporter.warning(
8532_error, _variable.documentation()->location(),
"Documentation tag @title and @author is only allowed on contract definitions. It will be disallowed in 0.7.0."
"Documentation tag @title and @author is only allowed on contract definitions. "
"It will be disallowed in 0.7.0."
);
}
return false;

View File

@ -209,14 +209,22 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier)
));
if (realName.empty())
{
m_errorReporter.declarationError(9553_error, _identifier.location, "In variable names _slot and _offset can only be used as a suffix.");
m_errorReporter.declarationError(
9553_error,
_identifier.location,
"In variable names _slot and _offset can only be used as a suffix."
);
return;
}
declarations = m_resolver.nameFromCurrentScope(realName);
}
if (declarations.size() > 1)
{
m_errorReporter.declarationError(8827_error, _identifier.location, "Multiple matching identifiers. Resolving overloaded identifiers is not supported.");
m_errorReporter.declarationError(
8827_error,
_identifier.location,
"Multiple matching identifiers. Resolving overloaded identifiers is not supported."
);
return;
}
else if (declarations.size() == 0)
@ -224,7 +232,11 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier)
if (auto var = dynamic_cast<VariableDeclaration const*>(declarations.front()))
if (var->isLocalVariable() && m_yulInsideFunction)
{
m_errorReporter.declarationError(8477_error, _identifier.location, "Cannot access local Solidity variables from inside an inline assembly function.");
m_errorReporter.declarationError(
8477_error,
_identifier.location,
"Cannot access local Solidity variables from inside an inline assembly function."
);
return;
}
@ -242,7 +254,11 @@ void ReferencesResolver::operator()(yul::VariableDeclaration const& _varDecl)
string namePrefix = identifier.name.str().substr(0, identifier.name.str().find('.'));
if (isSlot || isOffset)
m_errorReporter.declarationError(8820_error, identifier.location, "In variable declarations _slot and _offset can not be used as a suffix.");
m_errorReporter.declarationError(
8820_error,
identifier.location,
"In variable declarations _slot and _offset can not be used as a suffix."
);
else if (
auto declarations = m_resolver.nameFromCurrentScope(namePrefix);
!declarations.empty()

View File

@ -96,7 +96,10 @@ void DocStringParser::parse(string const& _docString, ErrorReporter& _errorRepor
auto tagNameEndPos = firstWhitespaceOrNewline(tagPos, end);
if (tagNameEndPos == end)
{
m_errorReporter->docstringParsingError(9222_error, "End of tag " + string(tagPos, tagNameEndPos) + " not found");
m_errorReporter->docstringParsingError(
9222_error,
"End of tag " + string(tagPos, tagNameEndPos) + " not found"
);
break;
}