Skip to content

Commit 4247843

Browse files
committed
Ruby: Adjust the scope of singleton class targets
In ```rb class << x ... end ``` the scope of `x` is not the singleton class itself, but rather the outer scope.
1 parent 87db5fc commit 4247843

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

ruby/ql/lib/codeql/ruby/AST.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ class AstNode extends TAstNode {
6060
final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
6161

6262
/** Gets the enclosing module, if any. */
63-
ModuleBase getEnclosingModule() { result = getEnclosingModule(scopeOfInclSynth(this)) }
63+
final ModuleBase getEnclosingModule() { result = getEnclosingModule(scopeOfInclSynth(this)) }
6464

6565
/** Gets the enclosing method, if any. */
66-
MethodBase getEnclosingMethod() { result = getEnclosingMethod(scopeOfInclSynth(this)) }
66+
final MethodBase getEnclosingMethod() { result = getEnclosingMethod(scopeOfInclSynth(this)) }
6767

6868
/** Gets a textual representation of this node. */
6969
cached

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private AstNode specialParentOfInclSynth(AstNode n) {
128128
n =
129129
[
130130
result.(Namespace).getScopeExpr(), result.(ClassDeclaration).getSuperclassExpr(),
131-
result.(SingletonMethod).getObject()
131+
result.(SingletonMethod).getObject(), result.(SingletonClass).getValue()
132132
]
133133
}
134134

ruby/ql/test/library-tests/modules/modules.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ enclosingModule
712712
| modules.rb:116:7:117:9 | YY | modules.rb:115:1:121:3 | XX |
713713
| modules.rb:116:18:116:19 | YY | modules.rb:115:1:121:3 | XX |
714714
| modules.rb:119:7:120:9 | class << ... | modules.rb:115:1:121:3 | XX |
715-
| modules.rb:119:16:119:19 | self | modules.rb:119:7:120:9 | class << ... |
715+
| modules.rb:119:16:119:19 | self | modules.rb:115:1:121:3 | XX |
716716
| modules.rb:123:1:124:3 | Baz | modules.rb:1:1:129:4 | modules.rb |
717717
| modules.rb:123:8:123:11 | Test | modules.rb:1:1:129:4 | modules.rb |
718718
| modules.rb:123:8:123:17 | Foo1 | modules.rb:1:1:129:4 | modules.rb |
@@ -722,7 +722,7 @@ enclosingModule
722722
| modules.rb:126:6:126:7 | XX | modules.rb:1:1:129:4 | modules.rb |
723723
| modules.rb:126:6:126:11 | call to new | modules.rb:1:1:129:4 | modules.rb |
724724
| modules.rb:128:1:129:3 | class << ... | modules.rb:1:1:129:4 | modules.rb |
725-
| modules.rb:128:10:128:11 | xx | modules.rb:128:1:129:3 | class << ... |
725+
| modules.rb:128:10:128:11 | xx | modules.rb:1:1:129:4 | modules.rb |
726726
| modules_rec.rb:1:1:2:3 | A | modules_rec.rb:1:1:11:26 | modules_rec.rb |
727727
| modules_rec.rb:1:7:1:7 | B | modules_rec.rb:1:1:11:26 | modules_rec.rb |
728728
| modules_rec.rb:4:1:5:3 | B | modules_rec.rb:1:1:11:26 | modules_rec.rb |

0 commit comments

Comments
 (0)