diff --git a/libs/remix-analyzer/src/solidity-analyzer/modules/similarVariableNames.ts b/libs/remix-analyzer/src/solidity-analyzer/modules/similarVariableNames.ts index abdca6d408..061b5ab70b 100644 --- a/libs/remix-analyzer/src/solidity-analyzer/modules/similarVariableNames.ts +++ b/libs/remix-analyzer/src/solidity-analyzer/modules/similarVariableNames.ts @@ -4,6 +4,7 @@ import { default as algorithm } from './algorithmCategories' import AbstractAst from './abstractAstView' import { get } from 'fast-levenshtein' import { util } from '@remix-project/remix-lib' +import { AstWalker } from '@remix-project/remix-astwalker' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, ContractHLAst, FunctionHLAst, VariableDeclarationAstNode, VisitFunction, ReportFunction, SupportedVersion} from './../../types' interface SimilarRecord { @@ -43,13 +44,20 @@ export default class similarVariableNames implements AnalyzerModule { if (multipleContractsWithSameName) { multipleContractsWithSameNameComments = 'Note: Import aliases are currently not supported by this static analysis.' } - const vars: string[] = this.getFunctionVariables(contract, func).map(getDeclaredVariableName) this.findSimilarVarNames(vars).map((sim) => { - warnings.push({ - warning: `${funcName} : Variables have very similar names "${sim.var1}" and "${sim.var2}". ${hasModifiersComments} ${multipleContractsWithSameNameComments}`, - location: func.node['src'] - }) + if(func.node.implemented) { + const astWalker = new AstWalker() + const functionBody: any = func.node.body + astWalker.walk(functionBody, (node) => { + if (node.nodeType === "Identifier" && (node.name === sim.var1 || node.name === sim.var2)) { + warnings.push({ + warning: `${funcName} : Variables have very similar names "${sim.var1}" and "${sim.var2}". ${hasModifiersComments} ${multipleContractsWithSameNameComments}`, + location: func.node['src'] + }) + } + }) + } }) }) })