Skip to content

Commit 3a8e2db

Browse files
authored
Merge pull request #7121 from hvitved/ruby/lookup-const-anti-join
2 parents ed3e539 + 19e6da5 commit 3a8e2db

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ruby/ql/lib/codeql/ruby/ast/internal/Module.qll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ private module Cached {
106106
exists(string qname | qname = resolveConstant(r) and result = TResolved(qname))
107107
}
108108

109+
pragma[nomagic]
110+
private string constantDefinition1(ConstantReadAccess r) {
111+
exists(ConstantWriteAccess w | result = constantDefinition0(w) |
112+
r = w.getScopeExpr()
113+
or
114+
r = w.(ClassDeclaration).getSuperclassExpr()
115+
)
116+
}
117+
109118
/**
110119
* Resolve constant access (class, module or otherwise) to a qualified module name.
111120
* `resolveScopeExpr/1` picks the best (lowest priority number) result of
@@ -121,11 +130,7 @@ private module Cached {
121130
isDefinedConstant(qn) and
122131
qn = resolveScopeExpr(r, p) and
123132
// prevent classes/modules that contain/extend themselves
124-
not exists(ConstantWriteAccess w | qn = constantDefinition0(w) |
125-
r = w.getScopeExpr()
126-
or
127-
r = w.(ClassDeclaration).getSuperclassExpr()
128-
)
133+
not qn = constantDefinition1(r)
129134
|
130135
qn order by p
131136
)

0 commit comments

Comments
 (0)