Merge pull request #11983 from ethereum/fix-fatal-error-hiding-non-fatal-errors-in-standard-json

Don't discard non-fatal errors in Yul mode in Standard JSON when followed by a fatal error
This commit is contained in:
chriseth 2021-09-20 11:53:09 +02:00 committed by GitHub
commit c9f98f2cc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 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

@ -0,0 +1 @@
--pretty-json --json-indent 4 --allow-paths .

View File

@ -0,0 +1,6 @@
{
"language": "Yul",
"sources": {
"C": {"urls": ["in.yul"]}
}
}

View File

@ -0,0 +1,19 @@
{
"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.",
"message": "Yul mode only supports exactly one input file.",
"severity": "error",
"type": "JSONError"
}
]
}