@@ -175,6 +175,18 @@ private module ThisFlow {
175175 result = strictcount ( int primaryParamPos | primaryConstructorThisAccess ( _, bb , primaryParamPos ) )
176176 }
177177
178+ private module BodyNearestLocationInput implements NearestLocationInputSig {
179+ class C = ControlFlowElement ;
180+
181+ predicate relevantLocations ( ControlFlowElement body , Location l1 , Location l2 ) {
182+ exists ( DataFlowCallable c |
183+ any ( InstanceParameterNode p ) .isParameterOf ( c , _) and
184+ body = c .asCallable ( l1 ) .getBody ( ) and
185+ l2 = body .getLocation ( )
186+ )
187+ }
188+ }
189+
178190 private predicate thisAccess ( Node n , BasicBlock bb , int i ) {
179191 thisAccess ( n , bb .getNode ( i ) )
180192 or
@@ -183,21 +195,29 @@ private module ThisFlow {
183195 i = ppos - numberOfPrimaryConstructorParameters ( bb )
184196 )
185197 or
186- exists ( DataFlowCallable c , EntryBasicBlock entry |
187- n .( InstanceParameterNode ) .isParameterOf ( c , _) and
188- exists ( ControlFlowNode succ |
189- succ = c .getAControlFlowNode ( ) and
190- succ = entry .getFirstNode ( ) .getASuccessor ( ) and
198+ exists ( Callable c , InstanceParameterNode p , Location l |
199+ p = n and
200+ c = p .getCallable ( l ) and
201+ (
191202 // In case `c` has multiple bodies, we want each body to gets its own implicit
192- // entry definition. In case `c` doesn't have multiple bodies, the line below
193- // is simply the same as `bb = entry`, because `entry.getFirstNode().getASuccessor()`
194- // will be in the entry block.
195- bb = succ . getBasicBlock ( )
196- |
197- i = - 1 - numberOfPrimaryConstructorParameters ( bb )
203+ // entry definition.
204+ exists ( ControlFlowElement body |
205+ body = c . getBody ( ) and
206+ bb . getANode ( ) . isBefore ( body ) and
207+ NearestLocation < BodyNearestLocationInput > :: nearestLocation ( body , l , _ )
208+ )
198209 or
199- not exists ( numberOfPrimaryConstructorParameters ( bb ) ) and i = - 1
210+ not c .hasBody ( ) and
211+ exists ( EntryBasicBlock entry , ControlFlowNode succ |
212+ succ = p .getEnclosingCallableImpl ( ) .getAControlFlowNode ( ) and
213+ succ = entry .getFirstNode ( ) .getASuccessor ( ) and
214+ bb = succ .getBasicBlock ( )
215+ )
200216 )
217+ |
218+ i = - 1 - numberOfPrimaryConstructorParameters ( bb )
219+ or
220+ not exists ( numberOfPrimaryConstructorParameters ( bb ) ) and i = - 1
201221 )
202222 }
203223
0 commit comments