@@ -49,6 +49,7 @@ private class MethodModifier extends MethodCall {
49
49
Expr getMethodArgument ( ) { result = this .getArgument ( 0 ) }
50
50
51
51
/** Holds if this call modifies a method with name `name` in namespace `n`. */
52
+ pragma [ noinline]
52
53
predicate modifiesMethod ( Namespace n , string name ) {
53
54
this = n .getAStmt ( ) and
54
55
[
@@ -139,7 +140,10 @@ class Method extends MethodBase, TMethod {
139
140
* ```
140
141
*/
141
142
override predicate isPrivate ( ) {
142
- any ( Private p ) .modifiesMethod ( this .getEnclosingModule ( ) , this .getName ( ) )
143
+ exists ( Namespace n , string name |
144
+ any ( Private p ) .modifiesMethod ( n , name ) and
145
+ isDeclaredIn ( this , n , name )
146
+ )
143
147
or
144
148
// Top-level methods are private members of the Object class
145
149
this .getEnclosingModule ( ) instanceof Toplevel
@@ -152,6 +156,14 @@ class Method extends MethodBase, TMethod {
152
156
final override string toString ( ) { result = this .getName ( ) }
153
157
}
154
158
159
+ /**
160
+ * Holds if the method `m` has name `name` and is declared in namespace `n`.
161
+ */
162
+ pragma [ noinline]
163
+ private predicate isDeclaredIn ( MethodBase m , Namespace n , string name ) {
164
+ n = m .getEnclosingModule ( ) and name = m .getName ( )
165
+ }
166
+
155
167
/** A singleton method. */
156
168
class SingletonMethod extends MethodBase , TSingletonMethod {
157
169
private Ruby:: SingletonMethod g ;
@@ -205,7 +217,10 @@ class SingletonMethod extends MethodBase, TSingletonMethod {
205
217
* ```
206
218
*/
207
219
override predicate isPrivate ( ) {
208
- any ( PrivateClassMethod p ) .modifiesMethod ( this .getEnclosingModule ( ) , this .getName ( ) )
220
+ exists ( Namespace n , string name |
221
+ any ( PrivateClassMethod p ) .modifiesMethod ( n , name ) and
222
+ isDeclaredIn ( this , n , name )
223
+ )
209
224
}
210
225
}
211
226
0 commit comments