Skip to content

Commit 3580a7a

Browse files
committed
AsmAnalyzer::analyzeStrictAssertCorrect(): Print source and errors when analysis fails
1 parent 91bc645 commit 3580a7a

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

libyul/AsmAnalysis.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,36 @@ AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(
113113
{},
114114
std::move(_objectStructure)
115115
).analyze(_astRoot);
116-
yulAssert(success && !errors.hasErrors(), "Invalid assembly/yul code.");
116+
117+
if (!success)
118+
{
119+
auto formatErrors = [](ErrorList const& _errorList) {
120+
std::vector<std::string> formattedErrors;
121+
for (std::shared_ptr<Error const> const& error: _errorList)
122+
{
123+
yulAssert(error->comment());
124+
formattedErrors.push_back(fmt::format(
125+
// Intentionally not showing source locations because we don't have the original
126+
// source here and it's unlikely they match the pretty-printed version.
127+
// They may not even match the original source if the AST was modified by the optimizer.
128+
"- {} {}: {}",
129+
Error::formatErrorType(error->type()),
130+
error->errorId().error,
131+
*error->comment()
132+
));
133+
}
134+
return joinHumanReadable(formattedErrors, "\n");
135+
};
136+
137+
yulAssert(errors.hasErrors(), "Yul analysis failed but did not report any errors.");
138+
yulAssert(false, fmt::format(
139+
"{}\n\nExpected valid Yul, but errors were reported during analysis:\n{}",
140+
AsmPrinter{_dialect}(_astRoot),
141+
formatErrors(errorList)
142+
));
143+
}
144+
145+
yulAssert(!errors.hasErrors());
117146
return analysisInfo;
118147
}
119148

0 commit comments

Comments
 (0)