@@ -173,14 +173,13 @@ class Method extends MethodBase, TMethod {
173
173
result = this .getExplicitVisibilityModifier ( )
174
174
or
175
175
not exists ( this .getExplicitVisibilityModifier ( ) ) and
176
- result .getEnclosingModule ( ) = this .getEnclosingModule ( ) and
177
- exists ( Namespace n , int methodPos | n .getStmt ( methodPos ) = this |
176
+ exists ( Namespace n , int methodPos | isDeclaredIn ( this , n , methodPos ) |
178
177
// The relevant visibility modifier is the closest call that occurs before
179
178
// the definition of `m` (typically this means higher up the file).
180
179
result =
181
180
max ( int modifierPos , VisibilityModifier modifier |
182
181
modifier .modifiesAmbientVisibility ( ) and
183
- n . getStmt ( modifierPos ) = modifier and
182
+ isDeclaredIn ( modifier , n , modifierPos ) and
184
183
modifierPos < methodPos
185
184
|
186
185
modifier order by modifierPos
@@ -205,11 +204,20 @@ class Method extends MethodBase, TMethod {
205
204
VisibilityModifier getExplicitVisibilityModifier ( ) {
206
205
result .getMethodArgument ( ) = this
207
206
or
208
- result . getEnclosingModule ( ) = this .getEnclosingModule ( ) and
207
+ isDeclaredIn ( result , this .getEnclosingModule ( ) , _ ) and
209
208
result .getMethodArgument ( ) .getConstantValue ( ) .getStringlikeValue ( ) = this .getName ( )
210
209
}
211
210
}
212
211
212
+ /**
213
+ * Holds if statement `m` is declared in namespace `n` at position `pos`.
214
+ */
215
+ pragma [ noinline]
216
+ private predicate isDeclaredIn ( Stmt m , Namespace n , int pos ) {
217
+ n = m .getEnclosingModule ( ) and
218
+ n .getStmt ( pos ) = m
219
+ }
220
+
213
221
/** A singleton method. */
214
222
class SingletonMethod extends MethodBase , TSingletonMethod {
215
223
private Ruby:: SingletonMethod g ;
0 commit comments