Skip to content

Commit 13fe5ba

Browse files
matheusaaguiarcameel
authored andcommitted
Replace errors/warning/info empty check with proper errors only check
1 parent 40758c3 commit 13fe5ba

File tree

11 files changed

+25
-21
lines changed

11 files changed

+25
-21
lines changed

liblangutil/ErrorReporter.h

+6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ class ErrorReporter
130130
return m_errorCount > 0;
131131
}
132132

133+
/// @returns true if there is any error, warning or info.
134+
bool hasErrorsWarningsOrInfos() const
135+
{
136+
return m_errorCount + m_warningCount + m_infoCount > 0;
137+
}
138+
133139
/// @returns the number of errors (ignores warnings and infos).
134140
unsigned errorCount() const
135141
{

liblangutil/Exceptions.h

+5
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ class Error: virtual public util::Exception
256256
return false;
257257
}
258258

259+
static bool hasErrorsWarningsOrInfos(ErrorList const& _list)
260+
{
261+
return !_list.empty();
262+
}
263+
259264
static std::string formatErrorSeverity(Severity _severity)
260265
{
261266
switch (_severity)

libsolidity/analysis/DeclarationTypeChecker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void DeclarationTypeChecker::endVisit(ArrayTypeName const& _typeName)
329329
Type const* baseType = _typeName.baseType().annotation().type;
330330
if (!baseType)
331331
{
332-
solAssert(!m_errorReporter.errors().empty(), "");
332+
solAssert(m_errorReporter.hasErrors(), "");
333333
return;
334334
}
335335

libsolidity/codegen/CompilerContext.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ void CompilerContext::appendInlineAssembly(
473473
dialect,
474474
identifierAccess.resolve
475475
).analyze(parserResult->root());
476-
if (!parserResult || !errorReporter.errors().empty() || !analyzerResult)
476+
if (!parserResult || errorReporter.hasErrorsWarningsOrInfos() || !analyzerResult)
477477
reportError("Invalid assembly generated by code generator.");
478478
std::shared_ptr<yul::AST const> toBeAssembledAST = parserResult;
479479

@@ -513,10 +513,10 @@ void CompilerContext::appendInlineAssembly(
513513
m_generatedYulUtilityCode = _assembly;
514514
}
515515

516-
if (!errorReporter.errors().empty())
516+
if (errorReporter.hasErrorsWarningsOrInfos())
517517
reportError("Failed to analyze inline assembly block.");
518518

519-
solAssert(errorReporter.errors().empty(), "Failed to analyze inline assembly block.");
519+
solAssert(!errorReporter.hasErrorsWarningsOrInfos(), "Failed to analyze inline assembly block.");
520520
yul::CodeGenerator::assemble(
521521
toBeAssembledAST->root(),
522522
analysisInfo,

libsolidity/interface/StandardCompiler.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -1621,14 +1621,7 @@ Json StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
16211621

16221622
// Inconsistent state - stop here to receive error reports from users
16231623
if (!stack.parseAndAnalyze(sourceName, sourceContents) && !stack.hasErrors())
1624-
{
1625-
output["errors"].emplace_back(formatError(
1626-
Error::Type::InternalCompilerError,
1627-
"general",
1628-
"No error reported, but compilation failed."
1629-
));
1630-
return output;
1631-
}
1624+
solAssert(false, "No error reported, but parsing/analysis failed.");
16321625

16331626
for (auto const& error: stack.errors())
16341627
{

libyul/YulStack.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ bool YulStack::parse(std::string const& _sourceName, std::string const& _source)
6464
reportUnimplementedFeatureError(_error);
6565
}
6666

67-
if (m_errorReporter.errors().empty())
67+
if (!m_errorReporter.hasErrors())
6868
m_stackState = Parsed;
6969

7070
return m_stackState == Parsed;

test/libsolidity/InlineAssembly.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void parsePrintCompare(std::string const& _source, bool _canWarn = false)
131131
if (_canWarn)
132132
BOOST_REQUIRE(!Error::containsErrors(stack.errors()));
133133
else
134-
BOOST_REQUIRE(stack.errors().empty());
134+
BOOST_REQUIRE(!Error::hasErrorsWarningsOrInfos(stack.errors()));
135135
std::string expectation = "object \"object\" {\n code " + boost::replace_all_copy(_source, "\n", "\n ") + "\n}\n";
136136
BOOST_CHECK_EQUAL(stack.print(), expectation);
137137
}
@@ -219,7 +219,7 @@ BOOST_AUTO_TEST_CASE(print_string_literal_unicode)
219219
DebugInfoSelection::None()
220220
);
221221
BOOST_REQUIRE(stack.parseAndAnalyze("", source));
222-
BOOST_REQUIRE(stack.errors().empty());
222+
BOOST_REQUIRE(!Error::hasErrorsWarningsOrInfos(stack.errors()));
223223
BOOST_CHECK_EQUAL(stack.print(), parsed);
224224

225225
std::string parsedInner = "{ let x := \"\\xe1\\xae\\xac\" }";

test/libyul/Common.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ std::pair<std::shared_ptr<AST const>, std::shared_ptr<yul::AsmAnalysisInfo>> yul
6161
solidity::frontend::OptimiserSettings::minimal(),
6262
DebugInfoSelection::All()
6363
);
64-
if (!stack.parseAndAnalyze("", _source) || !stack.errors().empty())
64+
if (!stack.parseAndAnalyze("", _source) || Error::hasErrorsWarningsOrInfos(stack.errors()))
6565
BOOST_FAIL("Invalid source.");
6666
return std::make_pair(stack.parserResult()->code(), stack.parserResult()->analysisInfo);
6767
}

test/tools/yulopti.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class YulOpti
9191
try
9292
{
9393
auto ast = yul::Parser(errorReporter, m_dialect).parse(_charStream);
94-
if (!m_astRoot || !errorReporter.errors().empty())
94+
if (!m_astRoot || errorReporter.hasErrors())
9595
{
9696
std::cerr << "Error parsing source." << std::endl;
9797
printErrors(_charStream, errors);
@@ -104,7 +104,7 @@ class YulOpti
104104
errorReporter,
105105
m_dialect
106106
);
107-
if (!analyzer.analyze(*m_astRoot) || !errorReporter.errors().empty())
107+
if (!analyzer.analyze(*m_astRoot) || errorReporter.hasErrors())
108108
{
109109
std::cerr << "Error analyzing source." << std::endl;
110110
printErrors(_charStream, errors);

test/tools/yulrun.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ std::pair<std::shared_ptr<AST const>, std::shared_ptr<AsmAnalysisInfo>> parse(st
6565
);
6666
if (stack.parseAndAnalyze("--INPUT--", _source))
6767
{
68-
yulAssert(stack.errors().empty(), "Parsed successfully but had errors.");
68+
yulAssert(!Error::hasErrorsWarningsOrInfos(stack.errors()), "Parsed successfully but had errors.");
6969
return make_pair(stack.parserResult()->code(), stack.parserResult()->analysisInfo);
7070
}
7171
else

tools/yulPhaser/Program.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ std::variant<std::unique_ptr<AST>, ErrorList> Program::parseObject(Dialect const
122122

123123
ObjectParser parser(errorReporter, _dialect);
124124
std::shared_ptr<Object> object = parser.parse(scanner, false);
125-
if (object == nullptr || !errorReporter.errors().empty())
125+
if (object == nullptr || errorReporter.hasErrors())
126126
// NOTE: It's possible to get errors even if the returned object is non-null.
127127
// For example when there are errors in a nested object.
128128
return errors;
@@ -165,7 +165,7 @@ std::variant<std::unique_ptr<AsmAnalysisInfo>, ErrorList> Program::analyzeAST(Di
165165
if (!analysisSuccessful)
166166
return errors;
167167

168-
assert(errorReporter.errors().empty());
168+
assert(!errorReporter.hasErrors());
169169
return std::variant<std::unique_ptr<AsmAnalysisInfo>, ErrorList>(std::move(analysisInfo));
170170
}
171171

0 commit comments

Comments
 (0)