Skip to content

Commit 92715ba

Browse files
committed
Attempt to fix bad join candidates
1 parent 5cdaae7 commit 92715ba

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,13 @@ class Method extends MethodBase, TMethod {
173173
result = this.getExplicitVisibilityModifier()
174174
or
175175
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) |
178177
// The relevant visibility modifier is the closest call that occurs before
179178
// the definition of `m` (typically this means higher up the file).
180179
result =
181180
max(int modifierPos, VisibilityModifier modifier |
182181
modifier.modifiesAmbientVisibility() and
183-
n.getStmt(modifierPos) = modifier and
182+
isDeclaredIn(modifier, n, modifierPos) and
184183
modifierPos < methodPos
185184
|
186185
modifier order by modifierPos
@@ -205,11 +204,20 @@ class Method extends MethodBase, TMethod {
205204
VisibilityModifier getExplicitVisibilityModifier() {
206205
result.getMethodArgument() = this
207206
or
208-
result.getEnclosingModule() = this.getEnclosingModule() and
207+
isDeclaredIn(result, this.getEnclosingModule(), _) and
209208
result.getMethodArgument().getConstantValue().getStringlikeValue() = this.getName()
210209
}
211210
}
212211

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+
213221
/** A singleton method. */
214222
class SingletonMethod extends MethodBase, TSingletonMethod {
215223
private Ruby::SingletonMethod g;

0 commit comments

Comments
 (0)