@@ -208,12 +208,12 @@ private predicate selfInModule(SelfVariable self, Module m) {
208
208
)
209
209
}
210
210
211
- /** Holds if `self` belongs to a method inside module `m`. */
211
+ /** Holds if `self` belongs to method ` method` inside module `m`. */
212
212
pragma [ nomagic]
213
- private predicate selfInMethod ( SelfVariable self , Module m ) {
214
- exists ( Scope scope , ModuleBase encl |
215
- scope = self .getDeclaringScope ( ) and
216
- encl = scope . ( MethodBase ) .getEnclosingModule ( ) and
213
+ private predicate selfInMethod ( SelfVariable self , MethodBase method , Module m ) {
214
+ exists ( ModuleBase encl |
215
+ method = self .getDeclaringScope ( ) and
216
+ encl = method .getEnclosingModule ( ) and
217
217
if encl instanceof SingletonClass
218
218
then m = encl .getEnclosingModule ( ) .getModule ( )
219
219
else m = encl .getModule ( )
@@ -354,7 +354,7 @@ private module Cached {
354
354
// end
355
355
// end
356
356
// ```
357
- selfInMethod ( sourceNode .( SsaSelfDefinitionNode ) .getVariable ( ) , m )
357
+ selfInMethod ( sourceNode .( SsaSelfDefinitionNode ) .getVariable ( ) , _ , m )
358
358
)
359
359
)
360
360
or
@@ -510,15 +510,17 @@ private DataFlow::Node trackInstance(Module tp, boolean exact, TypeTracker t) {
510
510
selfInModule ( sourceNode .( SsaSelfDefinitionNode ) .getVariable ( ) , tp )
511
511
or
512
512
// `self.new` inside a (singleton) method
513
- selfInMethod ( sourceNode .( SsaSelfDefinitionNode ) .getVariable ( ) , tp )
513
+ selfInMethod ( sourceNode .( SsaSelfDefinitionNode ) .getVariable ( ) , _ , tp )
514
514
)
515
515
or
516
516
// `self` reference in method or top-level (but not in module, where instance
517
517
// methods cannot be called; only singleton methods)
518
518
result =
519
519
any ( SsaSelfDefinitionNode self |
520
- selfInMethod ( self .getVariable ( ) , tp ) and
521
- exact = false
520
+ exists ( MethodBase m |
521
+ selfInMethod ( self .getVariable ( ) , m , tp ) and
522
+ if m .getEnclosingModule ( ) instanceof Toplevel then exact = true else exact = false
523
+ )
522
524
or
523
525
selfInToplevel ( self .getVariable ( ) , tp ) and
524
526
exact = true
@@ -535,7 +537,7 @@ private DataFlow::Node trackInstance(Module tp, boolean exact, TypeTracker t) {
535
537
selfInModule ( result .( SsaSelfDefinitionNode ) .getVariable ( ) , m )
536
538
or
537
539
// needed for e.g. `self.puts`
538
- selfInMethod ( result .( SsaSelfDefinitionNode ) .getVariable ( ) , m )
540
+ selfInMethod ( result .( SsaSelfDefinitionNode ) .getVariable ( ) , any ( SingletonMethod sm ) , m )
539
541
)
540
542
or
541
543
// `in C => c then c.foo`
0 commit comments