Skip to content

Commit 3a75b1d

Browse files
committed
Remove DeclarationTypeChecker class-specific error reporting functions
1 parent 32bec6b commit 3a75b1d

File tree

2 files changed

+15
-38
lines changed

2 files changed

+15
-38
lines changed

libsolidity/analysis/DeclarationTypeChecker.cpp

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ bool DeclarationTypeChecker::visit(ElementaryTypeName const& _typeName)
5050
_typeName.annotation().type = TypeProvider::address();
5151
break;
5252
default:
53-
typeError(
53+
m_errorReporter.typeError(
54+
2311_error,
5455
_typeName.location(),
5556
"Address types can only be payable or non-payable."
5657
);
@@ -102,7 +103,7 @@ bool DeclarationTypeChecker::visit(StructDefinition const& _struct)
102103
auto visitor = [&](StructDefinition const& _struct, auto& _cycleDetector, size_t _depth)
103104
{
104105
if (_depth >= 256)
105-
fatalDeclarationError(_struct.location(), "Struct definition exhausts cyclic dependency validator.");
106+
m_errorReporter.fatalDeclarationError(5651_error, _struct.location(), "Struct definition exhausts cyclic dependency validator.");
106107

107108
for (ASTPointer<VariableDeclaration> const& member: _struct.members())
108109
{
@@ -119,7 +120,7 @@ bool DeclarationTypeChecker::visit(StructDefinition const& _struct)
119120
}
120121
};
121122
if (util::CycleDetector<StructDefinition>(visitor).run(_struct) != nullptr)
122-
fatalTypeError(_struct.location(), "Recursive struct definition.");
123+
m_errorReporter.fatalTypeError(2046_error, _struct.location(), "Recursive struct definition.");
123124

124125
return false;
125126
}
@@ -145,7 +146,7 @@ void DeclarationTypeChecker::endVisit(UserDefinedTypeName const& _typeName)
145146
else
146147
{
147148
_typeName.annotation().type = TypeProvider::emptyTuple();
148-
fatalTypeError(_typeName.location(), "Name has to refer to a struct, enum or contract.");
149+
m_errorReporter.fatalTypeError(9755_error, _typeName.location(), "Name has to refer to a struct, enum or contract.");
149150
}
150151
}
151152
bool DeclarationTypeChecker::visit(FunctionTypeName const& _typeName)
@@ -165,13 +166,13 @@ bool DeclarationTypeChecker::visit(FunctionTypeName const& _typeName)
165166
case Visibility::External:
166167
break;
167168
default:
168-
fatalTypeError(_typeName.location(), "Invalid visibility, can only be \"external\" or \"internal\".");
169+
m_errorReporter.fatalTypeError(7653_error, _typeName.location(), "Invalid visibility, can only be \"external\" or \"internal\".");
169170
return false;
170171
}
171172

172173
if (_typeName.isPayable() && _typeName.visibility() != Visibility::External)
173174
{
174-
fatalTypeError(_typeName.location(), "Only external function types can be payable.");
175+
m_errorReporter.fatalTypeError(6138_error, _typeName.location(), "Only external function types can be payable.");
175176
return false;
176177
}
177178
_typeName.annotation().type = TypeProvider::function(_typeName);
@@ -226,7 +227,7 @@ void DeclarationTypeChecker::endVisit(ArrayTypeName const& _typeName)
226227
return;
227228
}
228229
if (baseType->storageBytes() == 0)
229-
fatalTypeError(_typeName.baseType().location(), "Illegal base type of storage size zero for array.");
230+
m_errorReporter.fatalTypeError(9390_error, _typeName.baseType().location(), "Illegal base type of storage size zero for array.");
230231
if (Expression const* length = _typeName.length())
231232
{
232233
TypePointer& lengthTypeGeneric = length->annotation().type;
@@ -235,13 +236,13 @@ void DeclarationTypeChecker::endVisit(ArrayTypeName const& _typeName)
235236
RationalNumberType const* lengthType = dynamic_cast<RationalNumberType const*>(lengthTypeGeneric);
236237
u256 lengthValue = 0;
237238
if (!lengthType || !lengthType->mobileType())
238-
typeError(length->location(), "Invalid array length, expected integer literal or constant expression.");
239+
m_errorReporter.typeError(8922_error, length->location(), "Invalid array length, expected integer literal or constant expression.");
239240
else if (lengthType->isZero())
240-
typeError(length->location(), "Array with zero length specified.");
241+
m_errorReporter.typeError(1220_error, length->location(), "Array with zero length specified.");
241242
else if (lengthType->isFractional())
242-
typeError(length->location(), "Array with fractional length specified.");
243+
m_errorReporter.typeError(4323_error, length->location(), "Array with fractional length specified.");
243244
else if (lengthType->isNegative())
244-
typeError(length->location(), "Array with negative length specified.");
245+
m_errorReporter.typeError(9308_error, length->location(), "Array with negative length specified.");
245246
else
246247
lengthValue = lengthType->literalValue(nullptr);
247248
_typeName.annotation().type = TypeProvider::array(DataLocation::Storage, baseType, lengthValue);
@@ -309,7 +310,7 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
309310
errorString += " for variable";
310311
}
311312
errorString += ", but " + locationToString(varLoc) + " was given.";
312-
typeError(_variable.location(), errorString);
313+
m_errorReporter.typeError(6160_error, _variable.location(), errorString);
313314

314315
solAssert(!allowedDataLocations.empty(), "");
315316
varLoc = *allowedDataLocations.begin();
@@ -359,24 +360,9 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
359360

360361
}
361362

362-
void DeclarationTypeChecker::typeError(SourceLocation const& _location, string const& _description)
363-
{
364-
m_errorReporter.typeError(2311_error, _location, _description);
365-
}
366-
367-
void DeclarationTypeChecker::fatalTypeError(SourceLocation const& _location, string const& _description)
368-
{
369-
m_errorReporter.fatalTypeError(5651_error, _location, _description);
370-
}
371-
372-
void DeclarationTypeChecker::fatalDeclarationError(SourceLocation const& _location, string const& _description)
373-
{
374-
m_errorReporter.fatalDeclarationError(2046_error, _location, _description);
375-
}
376-
377363
bool DeclarationTypeChecker::check(ASTNode const& _node)
378364
{
379-
unsigned errorCount = m_errorReporter.errorCount();
365+
auto watcher = m_errorReporter.errorWatcher();
380366
_node.accept(*this);
381-
return m_errorReporter.errorCount() == errorCount;
367+
return watcher.ok();
382368
}

libsolidity/analysis/DeclarationTypeChecker.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@ class DeclarationTypeChecker: private ASTConstVisitor
5959
void endVisit(VariableDeclaration const& _variable) override;
6060
bool visit(StructDefinition const& _struct) override;
6161

62-
/// Adds a new error to the list of errors.
63-
void typeError(langutil::SourceLocation const& _location, std::string const& _description);
64-
65-
/// Adds a new error to the list of errors and throws to abort reference resolving.
66-
void fatalTypeError(langutil::SourceLocation const& _location, std::string const& _description);
67-
68-
/// Adds a new error to the list of errors and throws to abort reference resolving.
69-
void fatalDeclarationError(langutil::SourceLocation const& _location, std::string const& _description);
70-
7162
langutil::ErrorReporter& m_errorReporter;
7263
langutil::EVMVersion m_evmVersion;
7364
bool m_insideFunctionType = false;

0 commit comments

Comments
 (0)