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.
This commit is contained in:
Tom Hvitved
2022-09-13 11:08:00 +02:00
parent 87db5fc6b1
commit 4247843a27
3 changed files with 5 additions and 5 deletions

View File

@@ -60,10 +60,10 @@ class AstNode extends TAstNode {
final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
/** Gets the enclosing module, if any. */
ModuleBase getEnclosingModule() { result = getEnclosingModule(scopeOfInclSynth(this)) }
final ModuleBase getEnclosingModule() { result = getEnclosingModule(scopeOfInclSynth(this)) }
/** Gets the enclosing method, if any. */
MethodBase getEnclosingMethod() { result = getEnclosingMethod(scopeOfInclSynth(this)) }
final MethodBase getEnclosingMethod() { result = getEnclosingMethod(scopeOfInclSynth(this)) }
/** Gets a textual representation of this node. */
cached

View File

@@ -128,7 +128,7 @@ private AstNode specialParentOfInclSynth(AstNode n) {
n =
[
result.(Namespace).getScopeExpr(), result.(ClassDeclaration).getSuperclassExpr(),
result.(SingletonMethod).getObject()
result.(SingletonMethod).getObject(), result.(SingletonClass).getValue()
]
}

View File

@@ -712,7 +712,7 @@ enclosingModule
| modules.rb:116:7:117:9 | YY | modules.rb:115:1:121:3 | XX |
| modules.rb:116:18:116:19 | YY | modules.rb:115:1:121:3 | XX |
| modules.rb:119:7:120:9 | class << ... | modules.rb:115:1:121:3 | XX |
| modules.rb:119:16:119:19 | self | modules.rb:119:7:120:9 | class << ... |
| modules.rb:119:16:119:19 | self | modules.rb:115:1:121:3 | XX |
| modules.rb:123:1:124:3 | Baz | modules.rb:1:1:129:4 | modules.rb |
| modules.rb:123:8:123:11 | Test | modules.rb:1:1:129:4 | modules.rb |
| modules.rb:123:8:123:17 | Foo1 | modules.rb:1:1:129:4 | modules.rb |
@@ -722,7 +722,7 @@ enclosingModule
| modules.rb:126:6:126:7 | XX | modules.rb:1:1:129:4 | modules.rb |
| modules.rb:126:6:126:11 | call to new | modules.rb:1:1:129:4 | modules.rb |
| modules.rb:128:1:129:3 | class << ... | modules.rb:1:1:129:4 | modules.rb |
| modules.rb:128:10:128:11 | xx | modules.rb:128:1:129:3 | class << ... |
| modules.rb:128:10:128:11 | xx | modules.rb:1:1:129:4 | modules.rb |
| modules_rec.rb:1:1:2:3 | A | modules_rec.rb:1:1:11:26 | modules_rec.rb |
| modules_rec.rb:1:7:1:7 | B | modules_rec.rb:1:1:11:26 | modules_rec.rb |
| modules_rec.rb:4:1:5:3 | B | modules_rec.rb:1:1:11:26 | modules_rec.rb |