Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
check local scoped references correctly.
  • Loading branch information
ryaneberly committed Dec 21, 2016
1 parent c2ee435 commit 1de7f66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/com/cflint/plugins/core/UnusedLocalVarChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@ public class UnusedLocalVarChecker extends CFLintScannerAdapter {
@Override
public void expression(final CFExpression expression, final Context context, final BugList bugs) {
if (expression instanceof CFFullVarExpression) {
final CFExpression variable = ((CFFullVarExpression) expression).getExpressions().get(0);
final CFFullVarExpression fullVarExpression = (CFFullVarExpression) expression;
final CFExpression variable = fullVarExpression.getExpressions().get(0);
if (variable instanceof CFIdentifier) {
final String name = ((CFIdentifier) variable).getName();
if (!scopes.isCFScoped(name) || scopes.isLocalScoped(name)) {
if (!scopes.isCFScoped(name)) {
localVariables.put(name, true);
}else if(scopes.isLocalScoped(name) && fullVarExpression.getExpressions().size()>1){
final CFExpression variable2 = fullVarExpression.getExpressions().get(1);
if (variable2 instanceof CFIdentifier) {
localVariables.put(((CFIdentifier) variable2).getName(), true);
}
}
}
for(CFExpression subexpr: ((CFFullVarExpression) expression).getExpressions()){
if(subexpr instanceof CFMember){
CFMember memberExpr = (CFMember) subexpr;
if(memberExpr.getExpression() != null) {
final String name = memberExpr.getExpression().toString();
if (!scopes.isCFScoped(name) || scopes.isLocalScoped(name)) {
localVariables.put(name, true);
}
expression(memberExpr.getExpression(),context,bugs);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/com/cflint/tests/UnusedVariable/forLoop_227.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
component{

public numeric function save( ) {

var x = {};
var a = local.x.foo;
return a.foo;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ ]

0 comments on commit 1de7f66

Please sign in to comment.