Commit 5edcdf8c authored by aniket-engg's avatar aniket-engg

loop over dynamic array length will show warning

parent fa772c01
...@@ -8,9 +8,8 @@ function forLoopIteratesOverDynamicArray () { ...@@ -8,9 +8,8 @@ function forLoopIteratesOverDynamicArray () {
} }
forLoopIteratesOverDynamicArray.prototype.visit = function (node) { forLoopIteratesOverDynamicArray.prototype.visit = function (node) {
if (common.isForLoop(node) && if (common.isForLoop(node) && (common.isDynamicArrayLengthAccess(node.children[1].children[1]) ||
node.children[1].children[1].attributes.member_name === 'length' && (node.children[1].children[1].children && common.isDynamicArrayLengthAccess(node.children[1].children[1].children[0])))) {
node.children[1].children[1].children[0].attributes.type.indexOf('[]') !== -1) {
this.relevantNodes.push(node) this.relevantNodes.push(node)
} }
} }
......
...@@ -518,6 +518,15 @@ function isDynamicArrayAccess (node) { ...@@ -518,6 +518,15 @@ function isDynamicArrayAccess (node) {
} }
/** /**
* True if node accesses 'length' member of array
* @node {ASTNode} node to check for
* @return {bool}
*/
function isDynamicArrayLengthAccess (node) {
return node && nodeType(node, exactMatch(nodeTypes.MEMBERACCESS)) && (node.attributes.member_name === 'length') && node.children[0].attributes.type.indexOf('[]') !== -1
}
/**
* True if node is a delete instruction for an element from a dynamic array * True if node is a delete instruction for an element from a dynamic array
* @node {ASTNode} node to check for * @node {ASTNode} node to check for
* @return {bool} * @return {bool}
...@@ -1111,6 +1120,7 @@ module.exports = { ...@@ -1111,6 +1120,7 @@ module.exports = {
isAbiNamespaceCall: isAbiNamespaceCall, isAbiNamespaceCall: isAbiNamespaceCall,
isSpecialVariableAccess: isSpecialVariableAccess, isSpecialVariableAccess: isSpecialVariableAccess,
isDynamicArrayAccess: isDynamicArrayAccess, isDynamicArrayAccess: isDynamicArrayAccess,
isDynamicArrayLengthAccess: isDynamicArrayLengthAccess,
isIndexAccess: isIndexAccess, isIndexAccess: isIndexAccess,
isMappingIndexAccess: isMappingIndexAccess, isMappingIndexAccess: isMappingIndexAccess,
isSubScopeWithTopLevelUnAssignedBinOp: isSubScopeWithTopLevelUnAssignedBinOp, isSubScopeWithTopLevelUnAssignedBinOp: isSubScopeWithTopLevelUnAssignedBinOp,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment