@@ -270,23 +270,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
270
270
report.log(explained(_.isSubType(tp1, tp2, approx), short = false ))
271
271
}
272
272
// Eliminate LazyRefs before checking whether we have seen a type before
273
- val normalize = new TypeMap with CaptureSet .IdempotentCaptRefMap {
274
- val DerefLimit = 10
275
- var derefCount = 0
276
- def apply (t : Type ) = t match {
277
- case t : LazyRef =>
278
- // Dereference a lazyref to detect underlying matching types, but
279
- // be careful not to get into an infinite recursion. If recursion count
280
- // exceeds `DerefLimit`, approximate with `t` instead.
281
- derefCount += 1
282
- if t.evaluating || derefCount >= DerefLimit then t
283
- else try mapOver(t.ref) finally derefCount -= 1
284
- case tp : TypeVar =>
285
- tp
286
- case _ =>
287
- mapOver(t)
288
- }
289
- }
273
+ val normalize = eliminateLazyRefs
290
274
val p = (normalize(tp1), normalize(tp2))
291
275
! pendingSubTypes.nn.contains(p) && {
292
276
try {
@@ -3338,6 +3322,24 @@ object TypeComparer {
3338
3322
end CoveredStatus
3339
3323
type CoveredStatus = CoveredStatus .Repr
3340
3324
3325
+ def eliminateLazyRefs (using Context ) = new TypeMap with CaptureSet .IdempotentCaptRefMap {
3326
+ val DerefLimit = 10
3327
+ var derefCount = 0
3328
+ def apply (t : Type ) = t match {
3329
+ case t : LazyRef =>
3330
+ // Dereference a lazyref to detect underlying matching types, but
3331
+ // be careful not to get into an infinite recursion. If recursion count
3332
+ // exceeds `DerefLimit`, approximate with `t` instead.
3333
+ derefCount += 1
3334
+ if t.evaluating || derefCount >= DerefLimit then t
3335
+ else try mapOver(t.ref) finally derefCount -= 1
3336
+ case tp : TypeVar =>
3337
+ tp
3338
+ case _ =>
3339
+ mapOver(t)
3340
+ }
3341
+ }
3342
+
3341
3343
def topLevelSubType (tp1 : Type , tp2 : Type )(using Context ): Boolean =
3342
3344
comparing(_.topLevelSubType(tp1, tp2))
3343
3345
0 commit comments