@@ -268,10 +268,8 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
268
268
private module BaseTypes {
269
269
/**
270
270
* Holds if `baseMention` is a (transitive) base type mention of `sub`,
271
- * and type parameter `tp` (belonging to `sub`) is mentioned (implicitly)
272
- * at `path` inside the type that `baseMention` resolves to.
273
- *
274
- * For example, in
271
+ * and `t` is mentioned (implicitly) at `path` inside `baseMention`. For
272
+ * example, in
275
273
*
276
274
* ```csharp
277
275
* class C<T1> { }
@@ -283,88 +281,21 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
283
281
* class Sub<T4> : Mid<C<T4>> { } // Sub<T4> extends Base<C<C<T4>>
284
282
* ```
285
283
*
286
- * - `T3` is mentioned at `0.0 ` for immediate base type mention `Base<C<T3>>`
284
+ * - ``C`1`` is mentioned at `T2 ` for immediate base type mention `Base<C<T3>>`
287
285
* of `Mid`,
288
- * - `T4` is mentioned at `0.0` for immediate base type mention `Mid<C<T4>>`
289
- * of `Sub`, and
290
- * - `T4` is mentioned implicitly at `0.0.0` for transitive base type mention
291
- * `Base<C<T3>>` of `Sub`.
292
- */
293
- pragma [ nomagic]
294
- predicate baseTypeMentionHasTypeParameterAt (
295
- Type sub , TypeMention baseMention , TypePath path , TypeParameter tp
296
- ) {
297
- exists ( TypeMention immediateBaseMention , TypePath pathToTypeParam |
298
- tp = sub .getATypeParameter ( ) and
299
- immediateBaseMention = getABaseTypeMention ( sub ) and
300
- tp = immediateBaseMention .resolveTypeAt ( pathToTypeParam )
301
- |
302
- // immediate base class
303
- baseMention = immediateBaseMention and
304
- path = pathToTypeParam
305
- or
306
- // transitive base class
307
- exists ( Type immediateBase , TypePath prefix , TypePath suffix , TypeParameter mid |
308
- /*
309
- * Example:
310
- *
311
- * - `prefix = "0.0"`,
312
- * - `pathToTypeParam = "0.0"`,
313
- * - `suffix = "0"`,
314
- * - `path = "0.0.0"`
315
- *
316
- * ```csharp
317
- * class C<T1> { }
318
- *
319
- * class Base<T2> { }
320
- *
321
- * class Mid<T3> : Base<C<T3>> { }
322
- * // ^^^ `immediateBase`
323
- * // ^^ `mid`
324
- * // ^^^^^^^^^^^ `baseMention`
325
- *
326
- * class Sub<T4> : Mid<C<T4>> { }
327
- * // ^^^ `sub`
328
- * // ^^ `tp`
329
- * // ^^^^^^^^^^ `immediateBaseMention`
330
- * ```
331
- */
332
-
333
- immediateBase = resolveTypeMentionRoot ( immediateBaseMention ) and
334
- baseTypeMentionHasTypeParameterAt ( immediateBase , baseMention , prefix , mid ) and
335
- pathToTypeParam .isCons ( mid , suffix ) and
336
- path = prefix .append ( suffix )
337
- )
338
- )
339
- }
340
-
341
- /**
342
- * Holds if `baseMention` is a (transitive) base type mention of `sub`,
343
- * and `t`, which is not a type parameter of `sub`, is mentioned
344
- * (implicitly) at `path` inside `baseMention`. For example, in
345
- *
346
- * ```csharp
347
- * class C<T1> { }
348
- *
349
- * class Base<T2> { }
350
- *
351
- * class Mid<T3> : Base<C<T3>> { }
352
- *
353
- * class Sub<T4> : Mid<C<T4>> { } // Sub<T4> extends Base<C<C<T4>>
354
- * ```
355
- *
356
- * - ``C`1`` is mentioned at `0` for immediate base type mention `Base<C<T3>>`
286
+ * - `T3` is mentioned at `T2.T1` for immediate base type mention `Base<C<T3>>`
357
287
* of `Mid`,
358
- * - ``C`1`` is mentioned at `0 ` for immediate base type mention `Mid<C<T4>>`
288
+ * - ``C`1`` is mentioned at `T3 ` for immediate base type mention `Mid<C<T4>>`
359
289
* of `Sub`, and
360
- * - ``C`1`` is mentioned at `0` and implicitly at `0.0` for transitive base type
290
+ * - `T4` is mentioned at `T3.T1` for immediate base type mention `Mid<C<T4>>`
291
+ * of `Sub`, and
292
+ * - ``C`1`` is mentioned at `T2` and implicitly at `T2.T1` for transitive base type
361
293
* mention `Base<C<T3>>` of `Sub`.
294
+ * - `T4` is mentioned implicitly at `T2.T1.T1` for transitive base type mention
295
+ * `Base<C<T3>>` of `Sub`.
362
296
*/
363
297
pragma [ nomagic]
364
- predicate baseTypeMentionHasNonTypeParameterAt (
365
- Type sub , TypeMention baseMention , TypePath path , Type t
366
- ) {
367
- not t = sub .getATypeParameter ( ) and
298
+ predicate baseTypeMentionHasTypeAt ( Type sub , TypeMention baseMention , TypePath path , Type t ) {
368
299
exists ( TypeMention immediateBaseMention |
369
300
pragma [ only_bind_into ] ( immediateBaseMention ) =
370
301
getABaseTypeMention ( pragma [ only_bind_into ] ( sub ) )
@@ -375,16 +306,17 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
375
306
or
376
307
// transitive base class
377
308
exists ( Type immediateBase | immediateBase = resolveTypeMentionRoot ( immediateBaseMention ) |
378
- baseTypeMentionHasNonTypeParameterAt ( immediateBase , baseMention , path , t )
309
+ not t = immediateBase .getATypeParameter ( ) and
310
+ baseTypeMentionHasTypeAt ( immediateBase , baseMention , path , t )
379
311
or
380
312
exists ( TypePath path0 , TypePath prefix , TypePath suffix , TypeParameter tp |
381
313
/*
382
314
* Example:
383
315
*
384
- * - `prefix = "0.0 "`,
385
- * - `path0 = "0 "`,
316
+ * - `prefix = "T2.T1 "`,
317
+ * - `path0 = "T3 "`,
386
318
* - `suffix = ""`,
387
- * - `path = "0.0 "`
319
+ * - `path = "T2.T1 "`
388
320
*
389
321
* ```csharp
390
322
* class C<T1> { }
@@ -403,7 +335,8 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
403
335
* ```
404
336
*/
405
337
406
- baseTypeMentionHasTypeParameterAt ( immediateBase , baseMention , prefix , tp ) and
338
+ baseTypeMentionHasTypeAt ( immediateBase , baseMention , prefix , tp ) and
339
+ tp = immediateBase .getATypeParameter ( ) and
407
340
t = immediateBaseMention .resolveTypeAt ( path0 ) and
408
341
path0 .isCons ( tp , suffix ) and
409
342
path = prefix .append ( suffix )
@@ -578,22 +511,27 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
578
511
}
579
512
580
513
private module AccessBaseType {
581
- private predicate relevantAccess ( Access a , AccessPosition apos ) {
582
- exists ( Declaration target |
514
+ /**
515
+ * Holds if inferring types at `a` might depend on the type at `apos`
516
+ * having `baseMention` as a transitive base type mention.
517
+ */
518
+ private predicate relevantAccess ( Access a , AccessPosition apos , Type base ) {
519
+ exists ( Declaration target , DeclarationPosition dpos |
583
520
adjustedAccessType ( a , apos , target , _, _) and
584
- target .getDeclaredType ( _, _) instanceof TypeParameter
521
+ accessDeclarationPositionMatch ( apos , dpos ) and
522
+ declarationBaseType ( target , dpos , base , _, _)
585
523
)
586
524
}
587
525
588
526
pragma [ nomagic]
589
527
private Type inferRootType ( Access a , AccessPosition apos ) {
590
- relevantAccess ( a , apos ) and
528
+ relevantAccess ( a , apos , _ ) and
591
529
result = a .getInferredType ( apos , TypePath:: nil ( ) )
592
530
}
593
531
594
532
pragma [ nomagic]
595
533
private Type inferTypeAt ( Access a , AccessPosition apos , TypeParameter tp , TypePath suffix ) {
596
- relevantAccess ( a , apos ) and
534
+ relevantAccess ( a , apos , _ ) and
597
535
exists ( TypePath path0 |
598
536
result = a .getInferredType ( apos , path0 ) and
599
537
path0 .isCons ( tp , suffix )
@@ -634,11 +572,14 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
634
572
predicate hasBaseTypeMention (
635
573
Access a , AccessPosition apos , TypeMention baseMention , TypePath path , Type t
636
574
) {
575
+ relevantAccess ( a , apos , resolveTypeMentionRoot ( baseMention ) ) and
637
576
exists ( Type sub | sub = inferRootType ( a , apos ) |
638
- baseTypeMentionHasNonTypeParameterAt ( sub , baseMention , path , t )
577
+ not t = sub .getATypeParameter ( ) and
578
+ baseTypeMentionHasTypeAt ( sub , baseMention , path , t )
639
579
or
640
580
exists ( TypePath prefix , TypePath suffix , TypeParameter tp |
641
- baseTypeMentionHasTypeParameterAt ( sub , baseMention , prefix , tp ) and
581
+ tp = sub .getATypeParameter ( ) and
582
+ baseTypeMentionHasTypeAt ( sub , baseMention , prefix , tp ) and
642
583
t = inferTypeAt ( a , apos , tp , suffix ) and
643
584
path = prefix .append ( suffix )
644
585
)
0 commit comments