Skip to content

Commit a62ad50

Browse files
committed
Ruby: Make isCapturedAccess work with synthesized scopes
1 parent 135ee0d commit a62ad50

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

ruby/ql/lib/codeql/ruby/ast/Variable.qll

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LocalVariable extends Variable, TLocalVariable {
5151
*
5252
* `x` is a captured variable, whereas `y` is not.
5353
*/
54-
predicate isCaptured() { this.getAnAccess().isCapturedAccess() }
54+
final predicate isCaptured() { this.getAnAccess().isCapturedAccess() }
5555
}
5656

5757
/** A global variable. */
@@ -152,7 +152,7 @@ class LocalVariableAccess extends VariableAccess instanceof LocalVariableAccessI
152152
* the access to `x` in the first `puts x` is a captured access, while
153153
* the access to `x` in the second `puts x` is not.
154154
*/
155-
predicate isCapturedAccess() { isCapturedAccess(this) }
155+
final predicate isCapturedAccess() { isCapturedAccess(this) }
156156
}
157157

158158
/** An access to a local variable where the value is updated. */
@@ -200,10 +200,4 @@ class SelfVariableAccess extends LocalVariableAccess instanceof SelfVariableAcce
200200
}
201201

202202
/** An access to the `self` variable where the value is read. */
203-
class SelfVariableReadAccess extends SelfVariableAccess, VariableReadAccess {
204-
// We override the definition in `LocalVariableAccess` because it gives the
205-
// wrong result for synthesised `self` variables.
206-
override predicate isCapturedAccess() {
207-
this.getVariable().getDeclaringScope() != this.getCfgScope()
208-
}
209-
}
203+
class SelfVariableReadAccess extends SelfVariableAccess, VariableReadAccess { }

0 commit comments

Comments
 (0)