Skip to content

Commit 67b4bc4

Browse files
committed
ruby: remove some FPs from rb/useless-assignment-to-local
1 parent 279e9e2 commit 67b4bc4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ruby/ql/src/queries/variables/DeadStoreOfLocal.ql

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@
1212

1313
import codeql.ruby.AST
1414
import codeql.ruby.dataflow.SSA
15+
import codeql.ruby.ApiGraphs
1516

1617
class RelevantLocalVariableWriteAccess extends LocalVariableWriteAccess {
1718
RelevantLocalVariableWriteAccess() {
1819
not this.getVariable().getName().charAt(0) = "_" and
19-
not this = any(Parameter p).getAVariable().getDefiningAccess()
20+
not this = any(Parameter p).getAVariable().getDefiningAccess() and
21+
not exists(SuperCall s |
22+
s.getEnclosingCallable().getAParameter().getAVariable().getAnAccess() = this
23+
|
24+
// a call to 'super' without any arguments will pass on the parameter.
25+
// thus, the parameter is used, and the assignment is not useless.
26+
not exists(s.getAnArgument())
27+
) and
28+
not API::getTopLevelMember("ERB").getInstance().getAMethodCall("result").asExpr().getScope() =
29+
this.getCfgScope()
2030
}
2131
}
2232

0 commit comments

Comments
 (0)