@@ -147,11 +147,10 @@ private DataFlow::LocalSourceNode trackInstance(Module tp, TypeTracker t) {
147147 )
148148 or
149149 // `self` in singleton method
150- exists ( Self self , MethodBase enclosing , DataFlow :: Node objectNode |
150+ exists ( Self self , MethodBase enclosing |
151151 self = result .asExpr ( ) .getExpr ( ) and
152- singletonMethod ( enclosing , objectNode . asExpr ( ) . getExpr ( ) ) and
152+ flowsToSingletonMethodObject ( trackInstance ( tp ) , enclosing ) and
153153 enclosing = self .getEnclosingMethod ( ) and
154- trackInstance ( tp ) .flowsTo ( objectNode ) and
155154 not self .getEnclosingModule ( ) .getEnclosingMethod ( ) = enclosing
156155 )
157156 or
@@ -166,9 +165,7 @@ private DataFlow::LocalSourceNode trackInstance(Module tp, TypeTracker t) {
166165 // a module or class
167166 exists ( Module m |
168167 result = trackModule ( m ) and
169- if m .getADeclaration ( ) instanceof ClassDeclaration
170- then tp = TResolved ( "Class" )
171- else tp = TResolved ( "Module" )
168+ if m .isClass ( ) then tp = TResolved ( "Class" ) else tp = TResolved ( "Module" )
172169 )
173170 )
174171 or
@@ -197,13 +194,26 @@ private predicate singletonMethod(MethodBase method, Expr object) {
197194 )
198195}
199196
197+ pragma [ nomagic]
198+ private predicate flowsToSingletonMethodObject ( DataFlow:: LocalSourceNode nodeFrom , MethodBase method ) {
199+ exists ( DataFlow:: LocalSourceNode nodeTo |
200+ nodeFrom .flowsTo ( nodeTo ) and
201+ singletonMethod ( method , nodeTo .asExpr ( ) .getExpr ( ) )
202+ )
203+ }
204+
205+ pragma [ nomagic]
206+ private predicate moduleFlowsToSingletonMethodObject ( Module m , MethodBase method ) {
207+ flowsToSingletonMethodObject ( trackModule ( m ) , method )
208+ }
209+
200210pragma [ nomagic]
201211private DataFlow:: LocalSourceNode trackSingletonMethod0 ( MethodBase method , TypeTracker t ) {
202212 t .start ( ) and
203- exists ( DataFlow :: Node nodeTo | singletonMethod ( method , nodeTo . asExpr ( ) . getExpr ( ) ) |
204- result . flowsTo ( nodeTo )
213+ (
214+ flowsToSingletonMethodObject ( result , method )
205215 or
206- exists ( Module m | result = trackModule ( m ) and trackModule ( m ) . flowsTo ( nodeTo ) )
216+ exists ( Module m | result = trackModule ( m ) and moduleFlowsToSingletonMethodObject ( m , method ) )
207217 )
208218 or
209219 exists ( TypeTracker t2 | result = trackSingletonMethod0 ( method , t2 ) .track ( t2 , t ) )
0 commit comments