From ce0a216ddc662ba98295509e03ce5ad17d2d06d9 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 11 Oct 2019 19:32:45 +0530 Subject: [PATCH] delete from mapping will not show warning --- .../modules/deleteFromDynamicArray.js | 2 +- .../solidity-analyzer/modules/staticAnalysisCommon.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/remix-analyzer/src/solidity-analyzer/modules/deleteFromDynamicArray.js b/remix-analyzer/src/solidity-analyzer/modules/deleteFromDynamicArray.js index 9557deb1dc..0ce8f6e579 100644 --- a/remix-analyzer/src/solidity-analyzer/modules/deleteFromDynamicArray.js +++ b/remix-analyzer/src/solidity-analyzer/modules/deleteFromDynamicArray.js @@ -8,7 +8,7 @@ function deleteFromDynamicArray () { } deleteFromDynamicArray.prototype.visit = function (node) { - if (common.isDeleteFromDynamicArray(node)) this.relevantNodes.push(node) + if (common.isDeleteFromDynamicArray(node) && !common.isMappingIndexAccess(node.children[0])) this.relevantNodes.push(node) } deleteFromDynamicArray.prototype.report = function (compilationResults) { diff --git a/remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.js b/remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.js index c49bc19a22..a5deed52a4 100644 --- a/remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.js +++ b/remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.js @@ -535,6 +535,15 @@ function isIndexAccess (node) { return node && node.name === 'IndexAccess' } +/** + * True if node is the access of a mapping index + * @node {ASTNode} node to check for + * @return {bool} + */ +function isMappingIndexAccess (node) { + return isIndexAccess(node) && node.children && node.children[0].attributes.type.startsWith('mapping') +} + /** * True if call to code within the current contracts context including (delegate) library call * @node {ASTNode} some AstNode @@ -1103,6 +1112,7 @@ module.exports = { isSpecialVariableAccess: isSpecialVariableAccess, isDynamicArrayAccess: isDynamicArrayAccess, isIndexAccess: isIndexAccess, + isMappingIndexAccess: isMappingIndexAccess, isSubScopeWithTopLevelUnAssignedBinOp: isSubScopeWithTopLevelUnAssignedBinOp, hasFunctionBody: hasFunctionBody, isInteraction: isInteraction,