Skip to content

Commit c860c2d

Browse files
committed
AsmAnalyzer::analyzeStrictAssertCorrect(): Print source and errors when analysis fails
1 parent 921572b commit c860c2d

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

libyul/AsmAnalysis.cpp

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

0 commit comments

Comments
 (0)