@@ -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,24 @@ 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 , Location l |
199+ c = n .( InstanceParameterNode ) .getCallable ( l ) and
200+ (
191201 // 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 )
202+ // entry definition.
203+ exists ( ControlFlowElement body |
204+ body = c . getBody ( ) and
205+ bb . getANode ( ) . isBefore ( body ) and
206+ NearestLocation < BodyNearestLocationInput > :: nearestLocation ( body , l , _ )
207+ )
198208 or
199- not exists ( numberOfPrimaryConstructorParameters ( bb ) ) and i = - 1
209+ not c .hasBody ( ) and
210+ bb .( EntryBasicBlock ) .getEnclosingCallable ( ) = c
200211 )
212+ |
213+ i = - 1 - numberOfPrimaryConstructorParameters ( bb )
214+ or
215+ not exists ( numberOfPrimaryConstructorParameters ( bb ) ) and i = - 1
201216 )
202217 }
203218
0 commit comments