@@ -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,17 @@ 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
191- // 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 )
198- or
199- not exists ( numberOfPrimaryConstructorParameters ( bb ) ) and i = - 1
200- )
198+ exists ( Callable c , Location l , ControlFlowElement body |
199+ c = n .( InstanceParameterNode ) .getCallable ( l ) and
200+ body = c .getBody ( ) and
201+ // In case `c` has multiple bodies, we want each body to gets its own implicit
202+ // entry definition.
203+ bb .getANode ( ) .isBefore ( body ) and
204+ NearestLocation< BodyNearestLocationInput > :: nearestLocation ( body , l , _)
205+ |
206+ i = - 1 - numberOfPrimaryConstructorParameters ( bb )
207+ or
208+ not exists ( numberOfPrimaryConstructorParameters ( bb ) ) and i = - 1
201209 )
202210 }
203211
0 commit comments