StandardCompiler: Do not discard non-fatal errors that happened before a fatal error

This commit is contained in:
Kamil Śliwak 2021-09-16 13:09:08 +02:00
parent 1a9ba1baca
commit fc8c4b046c
3 changed files with 60 additions and 13 deletions

View File

@ -28,6 +28,7 @@ Bugfixes:
* SMTChecker: Fix false positive in external calls from constructors.
* SMTChecker: Fix internal error on some multi-source uses of ``abi.*``, cryptographic functions and constants.
* SMTChecker: Fix BMC's constraints regarding internal functions.
* Standard JSON: Fix non-fatal errors in Yul mode being discarded if followed by a fatal error.
* Type Checker: Disallow modifier declarations and definitions in interfaces.
* Yul Optimizer: Fix a crash in LoadResolver, when ``keccak256`` has particular non-identifier arguments.

View File

@ -1312,16 +1312,49 @@ Json::Value StandardCompiler::compileSolidity(StandardCompiler::InputsAndSetting
Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
{
if (_inputsAndSettings.sources.size() != 1)
return formatFatalError("JSONError", "Yul mode only supports exactly one input file.");
if (!_inputsAndSettings.smtLib2Responses.empty())
return formatFatalError("JSONError", "Yul mode does not support smtlib2responses.");
if (!_inputsAndSettings.remappings.empty())
return formatFatalError("JSONError", "Field \"settings.remappings\" cannot be used for Yul.");
if (_inputsAndSettings.revertStrings != RevertStrings::Default)
return formatFatalError("JSONError", "Field \"settings.debug.revertStrings\" cannot be used for Yul.");
Json::Value output = Json::objectValue;
output["errors"] = std::move(_inputsAndSettings.errors);
if (_inputsAndSettings.sources.size() != 1)
{
output["errors"].append(formatError(
Error::Severity::Error,
"JSONError",
"general",
"Yul mode only supports exactly one input file."
));
return output;
}
if (!_inputsAndSettings.smtLib2Responses.empty())
{
output["errors"].append(formatError(
Error::Severity::Error,
"JSONError",
"general",
"Yul mode does not support smtlib2responses."
));
return output;
}
if (!_inputsAndSettings.remappings.empty())
{
output["errors"].append(formatError(
Error::Severity::Error,
"JSONError",
"general",
"Field \"settings.remappings\" cannot be used for Yul."
));
return output;
}
if (_inputsAndSettings.revertStrings != RevertStrings::Default)
{
output["errors"].append(formatError(
Error::Severity::Error,
"JSONError",
"general",
"Field \"settings.debug.revertStrings\" cannot be used for Yul."
));
return output;
}
AssemblyStack stack(
_inputsAndSettings.evmVersion,
@ -1333,16 +1366,23 @@ Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
// Inconsistent state - stop here to receive error reports from users
if (!stack.parseAndAnalyze(sourceName, sourceContents) && stack.errors().empty())
return formatFatalError("InternalCompilerError", "No error reported, but compilation failed.");
{
output["errors"].append(formatError(
Error::Severity::Error,
"InternalCompilerError",
"general",
"No error reported, but compilation failed."
));
return output;
}
if (!stack.errors().empty())
{
Json::Value errors = Json::arrayValue;
for (auto const& error: stack.errors())
{
auto err = dynamic_pointer_cast<Error const>(error);
errors.append(formatErrorWithException(
output["errors"].append(formatErrorWithException(
stack,
*error,
Error::errorSeverity(err->type()),
@ -1351,7 +1391,6 @@ Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
""
));
}
output["errors"] = errors;
return output;
}

View File

@ -1,6 +1,13 @@
{
"errors":
[
{
"component": "general",
"formattedMessage": "Cannot import url (\"in.yul\"): File not found.",
"message": "Cannot import url (\"in.yul\"): File not found.",
"severity": "error",
"type": "IOError"
},
{
"component": "general",
"formattedMessage": "Yul mode only supports exactly one input file.",