From 0757c48a3a9584a30bf3ad4a46a029dbe01f6159 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 3 Jun 2021 19:40:43 +0200 Subject: [PATCH] fix decode orphan struct definition --- .../src/solidity-decoder/astHelper.ts | 23 ++++++++++++++++++- .../src/solidity-decoder/decodeInfo.ts | 8 +++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/libs/remix-debug/src/solidity-decoder/astHelper.ts b/libs/remix-debug/src/solidity-decoder/astHelper.ts index abf2a3c16a..d3ecfa0c16 100644 --- a/libs/remix-debug/src/solidity-decoder/astHelper.ts +++ b/libs/remix-debug/src/solidity-decoder/astHelper.ts @@ -26,6 +26,27 @@ export function extractContractDefinitions (sourcesList) { return ret } +/** + * return nodes from an ast @arg sourcesList that are declared outside of a ContractDefinition @astList + * + * @param {Object} sourcesList - sources list (containing root AST node) + * @return {Object} - returns a list of node + */ +export function extractOrphanDefinitions (sourcesList) { + const ret = [] + for (const k in sourcesList) { + const ast = sourcesList[k].ast + if (ast.nodes && ast.nodes.length) { + for (const node of ast.nodes) { + if (node.nodeType !== 'ContractDefinition') { + ret.push(node) + } + } + } + } + return ret +} + /** * returns the linearized base contracts of the contract @arg id * @@ -54,7 +75,7 @@ export function extractStateDefinitions (contractName, sourcesList, contracts) { if (!node) { return null } - const stateItems = [] + const stateItems = extractOrphanDefinitions(sourcesList) const stateVar = [] const baseContracts = getLinearizedBaseContracts(node.id, contracts.contractsById) baseContracts.reverse() diff --git a/libs/remix-debug/src/solidity-decoder/decodeInfo.ts b/libs/remix-debug/src/solidity-decoder/decodeInfo.ts index ec5b31706d..5384b1af86 100644 --- a/libs/remix-debug/src/solidity-decoder/decodeInfo.ts +++ b/libs/remix-debug/src/solidity-decoder/decodeInfo.ts @@ -233,11 +233,11 @@ function getEnum (type, stateDefinitions, contractName) { * @return {Array} containing all members of the current struct type */ function getStructMembers (type, stateDefinitions, contractName, location) { - const split = type.split('.') - if (!split.length) { + if (type.indexOf('.') === -1) { type = contractName + '.' + type - } else { - contractName = split[0] + } + if (!contractName) { + contractName = type.split('.')[0] } const state = stateDefinitions[contractName] if (state) {