@@ -271,6 +271,20 @@ predicate unpackAndUnaliasInterfaceType(
271271
272272/** An interface type. */
273273class InterfaceType extends @interfacetype, CompositeType {
274+ private Type getMethodType ( int i , string name ) {
275+ i >= 0 and component_types ( this , i , name , result )
276+ }
277+
278+ /**
279+ * Holds if `tp` is a directly embedded type with index `index`.
280+ *
281+ * `tp` (or its underlying type) is either a type set literal type or an
282+ * interface type.
283+ */
284+ private predicate hasDirectlyEmbeddedType ( int index , Type tp ) {
285+ index >= 0 and component_types ( this , - ( index + 1 ) , _, tp )
286+ }
287+
274288 private InterfaceType getDeepUnaliasedTypeCandidate ( ) {
275289 exists (
276290 OptInterfaceComponent c0 , OptInterfaceComponent c1 , OptInterfaceComponent c2 ,
@@ -289,35 +303,32 @@ class InterfaceType extends @interfacetype, CompositeType {
289303 i = 5 or
290304 this .hasDeepUnaliasedComponentTypesUpTo ( unaliased , i - 1 )
291305 ) and
292- exists ( string name , Type tp | component_types ( this , i , name , tp ) |
293- component_types ( unaliased , i , name , tp .getDeepUnaliasedType ( ) )
306+ exists ( string name |
307+ unaliased . getMethodType ( i , name ) = this . getMethodType ( i , name ) .getDeepUnaliasedType ( )
294308 )
295309 }
296310
297311 private predicate hasDeepUnaliasedEmbeddedTypesUpTo ( InterfaceType unaliased , int i ) {
298312 unaliased = this .getDeepUnaliasedTypeCandidate ( ) and
299- i >= 3 and
313+ i >= 2 and
300314 (
301- i = 3 or
315+ i = 2 or
302316 this .hasDeepUnaliasedEmbeddedTypesUpTo ( unaliased , i - 1 )
303317 ) and
304- exists ( string name , Type tp | component_types ( this , - i , name , tp ) |
305- component_types ( unaliased , - i , name , tp .getDeepUnaliasedType ( ) )
318+ exists ( Type tp | this . hasDirectlyEmbeddedType ( i , tp ) |
319+ unaliased . hasDirectlyEmbeddedType ( i , tp .getDeepUnaliasedType ( ) )
306320 )
307321 }
308322
309323 override InterfaceType getDeepUnaliasedType ( ) {
310324 result = this .getDeepUnaliasedTypeCandidate ( ) and
311- exists ( int nComponents |
312- nComponents = count ( int i | component_types ( this , i , _, _) and i >= 0 )
313- |
325+ exists ( int nComponents | nComponents = count ( int i | exists ( this .getMethodType ( i , _) ) ) |
314326 this .hasDeepUnaliasedComponentTypesUpTo ( result , nComponents - 1 )
315327 or
316328 nComponents <= 5
317329 ) and
318- exists ( int nEmbeds | nEmbeds = count ( int i | component_types ( this , i , _, _) and i < 0 ) |
319- // Note no -1 here, because the first embedded type is at -1
320- this .hasDeepUnaliasedEmbeddedTypesUpTo ( result , nEmbeds )
330+ exists ( int nEmbeds | nEmbeds = count ( int i | this .hasDirectlyEmbeddedType ( i , _) ) |
331+ this .hasDeepUnaliasedEmbeddedTypesUpTo ( result , nEmbeds - 1 )
321332 or
322333 nEmbeds <= 2
323334 )
@@ -366,9 +377,7 @@ class TupleType extends @tupletype, CompositeType {
366377 or
367378 this .isDeepUnaliasedTypeUpTo ( tt , i - 1 )
368379 ) and
369- exists ( Type tp | component_types ( this , i , _, tp ) |
370- component_types ( tt , i , _, tp .getDeepUnaliasedType ( ) )
371- )
380+ tt .getComponentType ( i ) .getDeepUnaliasedType ( ) = this .getComponentType ( i )
372381 }
373382
374383 override TupleType getDeepUnaliasedType ( ) {
0 commit comments