@@ -49,6 +49,7 @@ private class MethodModifier extends MethodCall {
4949 Expr getMethodArgument ( ) { result = this .getArgument ( 0 ) }
5050
5151 /** Holds if this call modifies a method with name `name` in namespace `n`. */
52+ pragma [ noinline]
5253 predicate modifiesMethod ( Namespace n , string name ) {
5354 this = n .getAStmt ( ) and
5455 [
@@ -139,7 +140,10 @@ class Method extends MethodBase, TMethod {
139140 * ```
140141 */
141142 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+ )
143147 or
144148 // Top-level methods are private members of the Object class
145149 this .getEnclosingModule ( ) instanceof Toplevel
@@ -152,6 +156,14 @@ class Method extends MethodBase, TMethod {
152156 final override string toString ( ) { result = this .getName ( ) }
153157}
154158
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+
155167/** A singleton method. */
156168class SingletonMethod extends MethodBase , TSingletonMethod {
157169 private Ruby:: SingletonMethod g ;
@@ -205,7 +217,10 @@ class SingletonMethod extends MethodBase, TSingletonMethod {
205217 * ```
206218 */
207219 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+ )
209224 }
210225}
211226
0 commit comments