mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Improve error reporting for Yul parser errors
This makes debugging Sol2Yul codegen bugs slightly easier.
This commit is contained in:
parent
ec62d12319
commit
5a21e33743
@ -31,6 +31,9 @@
|
|||||||
|
|
||||||
#include <liblangutil/ErrorReporter.h>
|
#include <liblangutil/ErrorReporter.h>
|
||||||
|
|
||||||
|
#include <libsolutil/CommonData.h>
|
||||||
|
#include <libsolutil/StringUtils.h>
|
||||||
|
|
||||||
#include <boost/range/adaptor/reversed.hpp>
|
#include <boost/range/adaptor/reversed.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
@ -154,7 +157,12 @@ vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
|
|||||||
);
|
);
|
||||||
if (!found && watcher.ok())
|
if (!found && watcher.ok())
|
||||||
// Only add an error message if the callback did not do it.
|
// Only add an error message if the callback did not do it.
|
||||||
m_errorReporter.declarationError(8198_error, _identifier.location, "Identifier not found.");
|
m_errorReporter.declarationError(
|
||||||
|
8198_error,
|
||||||
|
_identifier.location,
|
||||||
|
"Identifier \"" + _identifier.name.str() + "\" not found."
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {type};
|
return {type};
|
||||||
@ -199,7 +207,9 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
|
|||||||
m_errorReporter.declarationError(
|
m_errorReporter.declarationError(
|
||||||
8678_error,
|
8678_error,
|
||||||
_assignment.location,
|
_assignment.location,
|
||||||
"Variable count does not match number of values (" +
|
"Variable count for assignment to \"" +
|
||||||
|
joinHumanReadable(applyMap(_assignment.variableNames, [](auto const& _identifier){ return _identifier.name.str(); })) +
|
||||||
|
"\" does not match number of values (" +
|
||||||
to_string(numVariables) +
|
to_string(numVariables) +
|
||||||
" vs. " +
|
" vs. " +
|
||||||
to_string(types.size()) +
|
to_string(types.size()) +
|
||||||
@ -235,7 +245,9 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
|
|||||||
m_errorReporter.declarationError(
|
m_errorReporter.declarationError(
|
||||||
3812_error,
|
3812_error,
|
||||||
_varDecl.location,
|
_varDecl.location,
|
||||||
"Variable count mismatch: " +
|
"Variable count mismatch for declaration of \"" +
|
||||||
|
joinHumanReadable(applyMap(_varDecl.variables, [](auto const& _identifier){ return _identifier.name.str(); })) +
|
||||||
|
+ "\": " +
|
||||||
to_string(numVariables) +
|
to_string(numVariables) +
|
||||||
" variables and " +
|
" variables and " +
|
||||||
to_string(types.size()) +
|
to_string(types.size()) +
|
||||||
@ -314,7 +326,11 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
|
|||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
if (!validateInstructions(_funCall))
|
if (!validateInstructions(_funCall))
|
||||||
m_errorReporter.declarationError(4619_error, _funCall.functionName.location, "Function not found.");
|
m_errorReporter.declarationError(
|
||||||
|
4619_error,
|
||||||
|
_funCall.functionName.location,
|
||||||
|
"Function \"" + _funCall.functionName.name.str() + "\" not found."
|
||||||
|
);
|
||||||
yulAssert(!watcher.ok(), "Expected a reported error.");
|
yulAssert(!watcher.ok(), "Expected a reported error.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +338,7 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
|
|||||||
m_errorReporter.typeError(
|
m_errorReporter.typeError(
|
||||||
7000_error,
|
7000_error,
|
||||||
_funCall.functionName.location,
|
_funCall.functionName.location,
|
||||||
"Function expects " +
|
"Function \"" + _funCall.functionName.name.str() + "\" expects " +
|
||||||
to_string(parameterTypes->size()) +
|
to_string(parameterTypes->size()) +
|
||||||
" arguments but got " +
|
" arguments but got " +
|
||||||
to_string(_funCall.arguments.size()) + "."
|
to_string(_funCall.arguments.size()) + "."
|
||||||
@ -421,7 +437,13 @@ void AsmAnalyzer::operator()(Switch const& _switch)
|
|||||||
|
|
||||||
/// Note: the parser ensures there is only one default case
|
/// Note: the parser ensures there is only one default case
|
||||||
if (watcher.ok() && !cases.insert(valueOfLiteral(*_case.value)).second)
|
if (watcher.ok() && !cases.insert(valueOfLiteral(*_case.value)).second)
|
||||||
m_errorReporter.declarationError(6792_error, _case.location, "Duplicate case defined.");
|
m_errorReporter.declarationError(
|
||||||
|
6792_error,
|
||||||
|
_case.location,
|
||||||
|
"Duplicate case \"" +
|
||||||
|
valueOfLiteral(*_case.value).str() +
|
||||||
|
"\" defined."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
(*this)(_case.body);
|
(*this)(_case.body);
|
||||||
|
Loading…
Reference in New Issue
Block a user