Fix ICE when requesting --combined-json outputs other than AST with --stop-after parsing

This commit is contained in:
Kamil Śliwak 2023-06-14 13:41:41 +02:00
parent b17757ea17
commit 36429e397c
4 changed files with 66 additions and 5 deletions

View File

@ -844,6 +844,9 @@ void CommandLineInterface::handleCombinedJSON()
output[g_strVersion] = frontend::VersionString;
vector<string> contracts = m_compiler->contractNames();
// NOTE: The state checks here are more strict that in Standard JSON. There we allow
// requesting certain outputs even if compilation fails as long as analysis went ok.
bool compilationSuccess = m_compiler->state() >= CompilerStack::State::CompilationSuccessful;
if (!contracts.empty())
@ -851,9 +854,9 @@ void CommandLineInterface::handleCombinedJSON()
for (string const& contractName: contracts)
{
Json::Value& contractData = output[g_strContracts][contractName] = Json::objectValue;
if (m_options.compiler.combinedJsonRequests->abi)
if (m_options.compiler.combinedJsonRequests->abi && compilationSuccess)
contractData[g_strAbi] = m_compiler->contractABI(contractName);
if (m_options.compiler.combinedJsonRequests->metadata)
if (m_options.compiler.combinedJsonRequests->metadata && compilationSuccess)
contractData["metadata"] = m_compiler->metadata(contractName);
if (m_options.compiler.combinedJsonRequests->binary && compilationSuccess)
contractData[g_strBinary] = m_compiler->object(contractName).toHex();
@ -887,11 +890,11 @@ void CommandLineInterface::handleCombinedJSON()
contractData[g_strFunDebugRuntime] = StandardCompiler::formatFunctionDebugData(
m_compiler->runtimeObject(contractName).functionDebugData
);
if (m_options.compiler.combinedJsonRequests->signatureHashes)
if (m_options.compiler.combinedJsonRequests->signatureHashes && compilationSuccess)
contractData[g_strSignatureHashes] = m_compiler->interfaceSymbols(contractName)["methods"];
if (m_options.compiler.combinedJsonRequests->natspecDev)
if (m_options.compiler.combinedJsonRequests->natspecDev && compilationSuccess)
contractData[g_strNatspecDev] = m_compiler->natspecDev(contractName);
if (m_options.compiler.combinedJsonRequests->natspecUser)
if (m_options.compiler.combinedJsonRequests->natspecUser && compilationSuccess)
contractData[g_strNatspecUser] = m_compiler->natspecUser(contractName);
}

View File

@ -0,0 +1 @@
--pretty-json --json-indent 4 --stop-after parsing --combined-json abi,asm,ast,bin,bin-runtime,devdoc,function-debug,function-debug-runtime,generated-sources,generated-sources-runtime,hashes,metadata,opcodes,srcmap,srcmap-runtime,storage-layout,userdoc

View File

@ -0,0 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity *;
contract C {}

View File

@ -0,0 +1,53 @@
{
"contracts":
{
"combined_json_stop_after_parsing/input.sol:C": {}
},
"sourceList":
[
"combined_json_stop_after_parsing/input.sol"
],
"sources":
{
"combined_json_stop_after_parsing/input.sol":
{
"AST":
{
"absolutePath": "combined_json_stop_after_parsing/input.sol",
"id": 3,
"license": "GPL-3.0",
"nodeType": "SourceUnit",
"nodes":
[
{
"id": 1,
"literals":
[
"solidity",
"*"
],
"nodeType": "PragmaDirective",
"src": "36:18:0"
},
{
"abstract": false,
"baseContracts": [],
"contractDependencies": [],
"contractKind": "contract",
"id": 2,
"name": "C",
"nameLocation": "65:1:0",
"nodeType": "ContractDefinition",
"nodes": [],
"src": "56:13:0",
"usedErrors": [],
"usedEvents": []
}
],
"src": "36:34:0"
},
"id": 0
}
},
"version": "<VERSION REMOVED>"
}